Skip to content

Commit 9aff0c3

Browse files
committed
feat(callgrind): add CALLGRIND_ADD_OBJ_SKIP client request
Add a trapdoor that lets the client register obj-skip paths at runtime, alongside the existing cmdline --obj-skip. Useful when the skip target isn't known statically (e.g. discovering the libpython path at Python startup). Extract CLG_(add_obj_to_skip) so the cmdline parser and the new client request share the same append-to-realloc'd-array logic.
1 parent 938e424 commit 9aff0c3

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

callgrind/callgrind.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ typedef
7878
VG_USERREQ__TOGGLE_COLLECT,
7979
VG_USERREQ__DUMP_STATS_AT,
8080
VG_USERREQ__START_INSTRUMENTATION,
81-
VG_USERREQ__STOP_INSTRUMENTATION
81+
VG_USERREQ__STOP_INSTRUMENTATION,
82+
VG_USERREQ__ADD_OBJ_SKIP
8283
} Vg_CallgrindClientRequest;
8384

8485
/* Dump current state of cost centers, and zero them afterwards */
@@ -126,4 +127,10 @@ typedef
126127
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STOP_INSTRUMENTATION, \
127128
0, 0, 0, 0, 0)
128129

130+
/* Add an object file path to the obj-skip list at runtime. Path matching
131+
is exact (same as --obj-skip=<path> on the command line). */
132+
#define CALLGRIND_ADD_OBJ_SKIP(path) \
133+
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__ADD_OBJ_SKIP, \
134+
path, 0, 0, 0, 0)
135+
129136
#endif /* __CALLGRIND_H */

callgrind/clo.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ void CLG_(update_fn_config)(fn_node* fn)
400400
}
401401

402402

403+
void CLG_(add_obj_to_skip)(const HChar* obj_name)
404+
{
405+
HChar* dup = VG_(strdup)("cl.clo.aots.1", obj_name);
406+
CLG_(clo).objs_to_skip_count++;
407+
CLG_(clo).objs_to_skip = VG_(realloc)("cl.clo.aots.2",
408+
CLG_(clo).objs_to_skip,
409+
CLG_(clo).objs_to_skip_count * sizeof(HChar*));
410+
CLG_(clo).objs_to_skip[CLG_(clo).objs_to_skip_count - 1] = dup;
411+
}
412+
413+
403414
/*--------------------------------------------------------------------*/
404415
/*--- Command line processing ---*/
405416
/*--------------------------------------------------------------------*/
@@ -431,12 +442,7 @@ Bool CLG_(process_cmd_line_option)(const HChar* arg)
431442
fnc->skip = CONFIG_TRUE;
432443
}
433444
else if VG_STR_CLO(arg, "--obj-skip", tmp_str) {
434-
HChar *obj_name = VG_(strdup)("cl.clo.pclo.1", tmp_str);
435-
CLG_(clo).objs_to_skip_count++;
436-
CLG_(clo).objs_to_skip = VG_(realloc)("cl.clo.pclo.2",
437-
CLG_(clo).objs_to_skip,
438-
CLG_(clo).objs_to_skip_count*sizeof(HChar*));
439-
CLG_(clo).objs_to_skip[CLG_(clo).objs_to_skip_count-1] = obj_name;
445+
CLG_(add_obj_to_skip)(tmp_str);
440446
}
441447

442448
else if VG_STR_CLO(arg, "--dump-before", tmp_str) {

callgrind/global.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ struct event_sets {
685685
void CLG_(set_clo_defaults)(void);
686686
void CLG_(update_fn_config)(fn_node*);
687687
Bool CLG_(process_cmd_line_option)(const HChar*);
688+
void CLG_(add_obj_to_skip)(const HChar* obj_name);
688689
void CLG_(print_usage)(void);
689690
void CLG_(print_debug_usage)(void);
690691

callgrind/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,13 @@ Bool CLG_(handle_client_request)(ThreadId tid, UWord *args, UWord *ret)
16801680
*ret = 0; /* meaningless */
16811681
break;
16821682

1683+
case VG_USERREQ__ADD_OBJ_SKIP: {
1684+
const HChar* path = (const HChar*)args[1];
1685+
CLG_(add_obj_to_skip)(path);
1686+
*ret = 0;
1687+
break;
1688+
}
1689+
16831690
case VG_USERREQ__GDB_MONITOR_COMMAND: {
16841691
Bool handled = handle_gdb_monitor_command (tid, (HChar*)args[1]);
16851692
if (handled)

0 commit comments

Comments
 (0)