Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
DiSL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DiSL
DiSL
Commits
7d511204
Commit
7d511204
authored
Dec 13, 2018
by
Lubomir Bulej
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow error checking functions to take format and arguments
parent
e14d1fda
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
37 deletions
+92
-37
src-disl-agent/common.c
src-disl-agent/common.c
+22
-7
src-disl-agent/common.h
src-disl-agent/common.h
+27
-12
src-disl-agent/dislagent.c
src-disl-agent/dislagent.c
+5
-5
src-disl-agent/jvmtiutil.c
src-disl-agent/jvmtiutil.c
+18
-9
src-disl-agent/jvmtiutil.h
src-disl-agent/jvmtiutil.h
+20
-4
No files found.
src-disl-agent/common.c
View file @
7d511204
...
...
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <assert.h>
...
...
@@ -31,8 +32,11 @@ find_value_index (const char * strval, const char * values [], int nvals) {
* an error code indicating a generic error.
*/
void
die_with_error
(
const
char
*
message
)
{
fprintf
(
stderr
,
"%s%s
\n
"
,
ERROR_PREFIX
,
message
);
die_with_error
(
const
char
*
restrict
format
,
va_list
args
)
{
fprintf
(
stderr
,
AGENT_NAME
": error: "
);
vfprintf
(
stderr
,
format
,
args
);
fprintf
(
stderr
,
"
\n
"
);
exit
(
ERROR_GENERIC
);
}
...
...
@@ -44,15 +48,22 @@ die_with_error (const char * message) {
* exits with an error code indicating failure in standard library call.
*/
void
die_with_std_error
(
const
char
*
message
,
int
errnum
)
{
die_with_std_error
(
int
errnum
,
const
char
*
restrict
format
,
va_list
args
)
{
char
*
cause
=
strerror
(
errnum
);
fprintf
(
stderr
,
"%s%s
\n
cause: %s
\n
"
,
ERROR_PREFIX
,
message
,
cause
);
fprintf
(
stderr
,
AGENT_NAME
": std-error: %s
\n
"
,
cause
);
fprintf
(
stderr
,
AGENT_NAME
": "
);
vfprintf
(
stderr
,
format
,
args
);
fprintf
(
stderr
,
"
\n
"
);
exit
(
ERROR_STD
);
}
// ****************************************************************************
// STRING UTILS SECTION
// ****************************************************************************
size_t
substr_count
(
const
char
*
string
,
const
char
*
restrict
substr
)
{
size_t
count
=
0
;
...
...
@@ -117,13 +128,17 @@ __get_error_message (const DWORD msg_id) {
* exits with an error code indicating failure in standard library call.
*/
void
die_with_win_error
(
const
char
*
message
,
DWORD
errnum
)
{
c
har
*
cause
=
__get_error_message
(
errnum
);
fprintf
(
stderr
,
"%s%s
\n
cause: %s"
,
ERROR_PREFIX
,
message
,
cause
);
die_with_win_error
(
DWORD
errnum
,
const
char
*
restrict
format
,
va_list
args
)
{
c
onst
char
*
restrict
cause
=
__get_error_message
(
errnum
);
fprintf
(
stderr
,
AGENT_NAME
": std-error: %s
\n
"
,
cause
);
if
(
cause
!=
NULL
)
{
free
(
cause
);
}
fprintf
(
stderr
,
AGENT_NAME
": "
);
vfprintf
(
stderr
,
format
,
args
);
fprintf
(
stderr
,
"
\n
"
);
exit
(
ERROR_STD
);
}
...
...
src-disl-agent/common.h
View file @
7d511204
...
...
@@ -4,9 +4,9 @@
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
#include <errno.h>
#include <sys/types.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
...
...
@@ -45,6 +45,7 @@
/**
* Prints a warning message to stderr.
*
* @format format string for printf
* @args arguments associated with the format string
...
...
@@ -66,12 +67,12 @@ int find_value_index (const char * strval, const char * values [], int nvals);
#define ERROR_STD 10002
#define ERROR_JVMTI 10003
#define
ERROR_PREFIX "disl-agent: error:
"
#define
AGENT_NAME "disl-agent
"
//
void
die_with_error
(
const
char
*
message
);
void
die_with_std_error
(
const
char
*
message
,
int
errnum
);
void
die_with_error
(
const
char
*
format
,
va_list
args
);
void
die_with_std_error
(
int
errnum
,
const
char
*
format
,
va_list
args
);
// ****************************************************************************
// STRING UTILS SECTION
...
...
@@ -103,9 +104,14 @@ split_string(char * string, const char * restrict separator, size_t * tokens);
* error condition is true.
*/
static
inline
void
check_error
(
bool
error
,
const
char
*
message
)
{
check_error
(
bool
error
,
const
char
*
format
,
...
)
{
if
(
error
)
{
die_with_error
(
message
);
va_list
args
;
va_start
(
args
,
format
);
die_with_error
(
format
,
args
);
va_end
(
args
);
}
}
...
...
@@ -115,9 +121,14 @@ check_error (bool error, const char * message) {
* error condition is true.
*/
static
inline
void
check_std_error
(
bool
error
,
const
char
*
message
)
{
check_std_error
(
bool
error
,
const
char
*
format
,
...
)
{
if
(
error
)
{
die_with_std_error
(
message
,
errno
);
va_list
args
;
va_start
(
args
,
format
);
die_with_std_error
(
errno
,
format
,
args
);
va_end
(
args
);
}
}
...
...
@@ -137,7 +148,7 @@ warn_std_error (bool error, const char * message) {
#ifdef MINGW
void
die_with_win_error
(
const
char
*
message
,
DWORD
errnum
);
void
die_with_win_error
(
DWORD
errnum
,
const
char
*
message
,
va_list
args
);
/**
...
...
@@ -145,13 +156,17 @@ void die_with_win_error (const char * message, DWORD errnum);
* error condition is true.
*/
static
inline
void
check_win_error
(
bool
error
,
const
char
*
message
)
{
check_win_error
(
bool
error
,
const
char
*
format
,
...
)
{
if
(
error
)
{
die_with_win_error
(
message
,
GetLastError
());
va_list
args
;
va_start
(
args
,
format
);
die_with_win_error
(
GetLastError
(),
format
,
args
);
va_end
(
args
);
}
}
#endif
/* MINGW */
#endif
/* _COMMON_H_ */
src-disl-agent/dislagent.c
View file @
7d511204
...
...
@@ -210,8 +210,8 @@ __instrument_class (
//
if
(
response
->
result
==
INSTRUMENT_CLASS_RESPONSE__INSTRUMENT_CLASS_RESULT__ERROR
)
{
fprintf
(
stderr
,
"%s
instrumentation server error:
\n
%s
\n
"
,
ERROR_PREFIX
,
response
->
errormessage
stderr
,
AGENT_NAME
":
instrumentation server error:
\n
%s
\n
"
,
response
->
errormessage
);
exit
(
ERROR_SERVER
);
...
...
@@ -709,11 +709,11 @@ __get_jvmti (JavaVM * jvm) {
// JVMTI interface. This is a fatal error for the agent.
//
fprintf
(
stderr
,
"
%s
Failed to obtain JVMTI interface Version 1 (0x%x)
\n
"
stderr
,
AGENT_NAME
"error: "
"Failed to obtain JVMTI interface Version 1 (0x%x)
\n
"
"JVM GetEnv() returned %ld - is your Java runtime "
"version 1.5 or newer?
\n
"
,
ERROR_PREFIX
,
JVMTI_VERSION_1
,
(
long
)
result
JVMTI_VERSION_1
,
(
long
)
result
);
exit
(
ERROR_JVMTI
);
...
...
src-disl-agent/jvmtiutil.c
View file @
7d511204
...
...
@@ -10,8 +10,8 @@
//
#ifndef
ERROR_PREFIX
#error
ERROR_PREFIX
macro has to be defined
#ifndef
AGENT_NAME
#error
AGENT_NAME
macro has to be defined
#endif
#ifndef ERROR_JVMTI
...
...
@@ -175,16 +175,25 @@ jvmti_get_system_property_string (
* interface.
*/
void
die_with_jvmti_error
(
jvmtiEnv
*
jvmti
,
jvmtiError
errnum
,
const
char
*
str
)
{
char
*
errnum_str
=
NULL
;
(
void
)
(
*
jvmti
)
->
GetErrorName
(
jvmti
,
errnum
,
&
errnum_str
);
die_with_jvmti_error
(
jvmtiEnv
*
jvmti
,
jvmtiError
error
,
const
char
*
restrict
format
,
va_list
args
)
{
// JVMTI error
char
*
cause
=
NULL
;
(
void
)
(
*
jvmti
)
->
GetErrorName
(
jvmti
,
error
,
&
cause
);
fprintf
(
stderr
,
"%sJVMTI: %d (%s): %s
\n
"
,
ERROR_PREFIX
,
errnum
,
(
errnum_str
==
NULL
?
"Unknown"
:
errnum_str
),
(
str
==
NULL
?
""
:
str
)
stderr
,
AGENT_NAME
": jvmti-error: %s (%d)
\n
"
,
(
cause
!=
NULL
)
?
cause
:
"unknown"
,
error
);
(
*
jvmti
)
->
Deallocate
(
jvmti
,
(
unsigned
char
*
)
cause
);
// agent error
fprintf
(
stderr
,
AGENT_NAME
": "
);
vfprintf
(
stderr
,
format
,
args
);
fprintf
(
stderr
,
"
\n
"
);
exit
(
ERROR_JVMTI
);
}
src-disl-agent/jvmtiutil.h
View file @
7d511204
...
...
@@ -3,12 +3,14 @@
#include "common.h"
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <jvmti.h>
//
void
die_with_jvmti_error
(
jvmtiEnv
*
jvmti
,
jvmtiError
error
,
const
char
*
message
);
unsigned
char
*
jvmti_alloc_copy
(
jvmtiEnv
*
jvmti
,
const
void
*
src
,
size_t
size
);
bool
jvmti_redefine_class
(
...
...
@@ -24,6 +26,12 @@ char * jvmti_get_system_property_string (
jvmtiEnv
*
jvmti
,
const
char
*
name
,
const
char
*
dflval
);
//
void
die_with_jvmti_error
(
jvmtiEnv
*
jvmti
,
jvmtiError
error
,
const
char
*
format
,
va_list
args
);
/**
* Checks whether a JVMTI invocation returned an error. Every JVMTI interface
...
...
@@ -31,9 +39,17 @@ char * jvmti_get_system_property_string (
* down the line.
*/
static
inline
void
check_jvmti_error
(
jvmtiEnv
*
jvmti
,
jvmtiError
errnum
,
const
char
*
message
)
{
check_jvmti_error
(
jvmtiEnv
*
restrict
jvmti
,
jvmtiError
errnum
,
const
char
*
restrict
format
,
...
)
{
if
(
errnum
!=
JVMTI_ERROR_NONE
)
{
die_with_jvmti_error
(
jvmti
,
errnum
,
message
);
va_list
args
;
va_start
(
args
,
format
);
die_with_jvmti_error
(
jvmti
,
errnum
,
format
,
args
);
va_end
(
args
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment