Skip to content

Commit ede3641

Browse files
committed
Debug/parser pull request changes
1 parent 594a0f1 commit ede3641

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

src/agent/agent.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ FILE* g_debug_fp;
4848
FILE* g_error_fp;
4949
FILE* g_output_fp;
5050
bool debugTypeEnabled [numDebugTypes] = {getenv("SP_DEBUG_INJECTOR"), getenv("SP_DEBUG_COMMON"), getenv("SP_DEBUG_PATCHAPI"), getenv("SP_DEBUG_IPC"), getenv("SP_DEBUG_WORKER"), getenv("SP_DEBUG_SIGTRAP"), getenv("SP_DEBUG_AGENT"), true};
51-
51+
bool sp_debug = getenv("SP_DEBUG");
52+
bool sp_fdebug = getenv("SP_FDEBUG");
5253

5354
namespace sp {
5455

@@ -69,7 +70,7 @@ namespace sp {
6970
core_limit.rlim_cur = RLIM_INFINITY;
7071
core_limit.rlim_max = RLIM_INFINITY;
7172
if (setrlimit(RLIMIT_CORE, &core_limit) < 0) {
72-
sp_perror("RROR: failed to setup core dump ability\n");
73+
sp_perror("ERROR: failed to setup core dump ability\n");
7374
}
7475
}
7576

src/agent/parser.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -789,27 +789,26 @@ SpParser::FindFunction(string name,
789789
// Find function by mangled name.
790790
FuncSet
791791
SpParser::FindFunctionByMangledName(string name) {
792-
793792
sp_debug_agent("LOOKING FOR FUNC BY MANGLED NAME - looking for %s",
794793
name.c_str());
795794

796-
FuncSet* found_funcs = new FuncSet();
795+
FuncSet found_funcs;
797796
if (name.length() == 0) {
798-
return *found_funcs;
797+
return found_funcs;
799798
}
800799

801800
// A quick return, if this function is in the cache
802801
if (mangled_func_map_.find(name) != mangled_func_map_.end()) {
803802
sp_debug_agent("GOT FROM CACHE - %s",
804803
FUNC_CAST((*mangled_func_map_[name].begin()))->GetMangledName().c_str());
805-
std::copy(mangled_func_map_[name].begin(), mangled_func_map_[name].end(), inserter(*found_funcs, found_funcs->begin()));
806-
return *found_funcs;
804+
std::copy(mangled_func_map_[name].begin(), mangled_func_map_[name].end(), inserter(found_funcs, found_funcs.begin()));
805+
return found_funcs;
807806
}
808807

809808
// A quick return, if this function is proved to be not found
810809
if (mangled_func_not_found_.find(name) != mangled_func_not_found_.end()) {
811810
sp_debug_agent("NOT FOUND - %s is proved to be not found", name.c_str());
812-
return *found_funcs;
811+
return found_funcs;
813812
}
814813

815814
// Iterate through each object to look for this function
@@ -839,15 +838,15 @@ SpParser::FindFunctionByMangledName(string name) {
839838
if (func_set.size() == 0) {
840839
mangled_func_not_found_.insert(name);
841840
sp_debug_agent("NO FOUND - %s", name.c_str());
842-
return *found_funcs;
841+
return found_funcs;
843842
}
844843

845844
//std::copy(func_set.begin(), func_set.end(), inserter(mangled_func_map_[name], mangled_func_map_[name].begin()));
846-
std::copy(func_set.begin(), func_set.end(), inserter(*found_funcs, found_funcs->begin()));
847-
assert(found_funcs->size() > 0);
848-
sp_debug_agent("FOUND - %lu instances of %s, first in object %s", found_funcs->size(), name.c_str(),
845+
std::copy(func_set.begin(), func_set.end(), inserter(found_funcs, found_funcs.begin()));
846+
assert(found_funcs.size() > 0);
847+
sp_debug_agent("FOUND - %lu instances of %s, first in object %s", found_funcs.size(), name.c_str(),
849848
FUNC_CAST((*func_set.begin()))->GetObject()->name().c_str());
850-
return *found_funcs;
849+
return found_funcs;
851850
}
852851

853852
// Find function by name.

src/common/common.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ extern FILE* g_output_fp;
5151
extern FILE* g_debug_fp;
5252
extern FILE* g_error_fp;
5353

54+
extern bool sp_debug;
55+
extern bool sp_fdebug;
5456
const int numDebugTypes = 8;
5557
enum DebugType {injectorDebug, commonDebug, patchapiDebug, ipcDebug, workerDebug, sigtrapDebug, agentDebug, unknownDebugType};
5658
extern bool debugTypeEnabled [numDebugTypes];
@@ -96,20 +98,18 @@ extern bool debugTypeEnabled [numDebugTypes];
9698
debugType = unknownDebugType; \
9799
} \
98100
if (debugTypeEnabled[debugType]) { \
99-
if (getenv("SP_DEBUG")) { \
101+
FILE* debug_fp; \
102+
if (sp_fdebug) \
103+
debug_fp = g_debug_fp; \
104+
else \
105+
debug_fp = stderr; \
106+
if (sp_debug || sp_fdebug) { \
100107
char* nodir = basename((char*)__FILE__); \
101-
fprintf(stderr, "%s [%d]: ", nodir, __LINE__); \
102-
fprintf(stderr, __VA_ARGS__); \
103-
fprintf(stderr, "\n"); \
104-
fflush(stderr); \
108+
fprintf(debug_fp, "%s [%d]: ", nodir, __LINE__); \
109+
fprintf(debug_fp, __VA_ARGS__); \
110+
fprintf(debug_fp, "\n"); \
111+
fflush(debug_fp); \
105112
} \
106-
else if (getenv("SP_FDEBUG")) { \
107-
char* nodir = basename((char*)__FILE__); \
108-
fprintf(g_debug_fp, "%s [%d]: ", nodir, __LINE__); \
109-
fprintf(g_debug_fp, __VA_ARGS__); \
110-
fprintf(g_debug_fp, "\n"); \
111-
fflush(g_debug_fp); \
112-
}\
113113
} \
114114
} while(0)
115115

src/injector/injector_main.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ FILE* g_debug_fp = stderr;
1111
FILE* g_error_fp = stderr;
1212
FILE* g_output_fp = stdout;
1313
bool debugTypeEnabled [numDebugTypes] = {getenv("SP_DEBUG_INJECTOR"), getenv("SP_DEBUG_COMMON"), getenv("SP_DEBUG_PATCHAPI"), getenv("SP_DEBUG_IPC"), getenv("SP_DEBUG_WORKER"), getenv("SP_DEBUG_SIGTRAP"), getenv("SP_DEBUG_AGENT"), true};
14-
14+
bool sp_debug = getenv("SP_DEBUG");
15+
bool sp_fdebug = getenv("SP_FDEBUG");
1516

1617
// Here we go!
1718
int main(int argc, char *argv[]) {

0 commit comments

Comments
 (0)