void VG_(gdbserver_status_output)(void) { const int nr_gdbserved_addresses = (gs_addresses == NULL ? -1 : VG_(HT_count_nodes) (gs_addresses)); const int nr_watchpoints = (gs_watches == NULL ? -1 : (int) VG_(sizeXA) (gs_watches)); remote_utils_output_status(); VG_(umsg) ("nr of calls to gdbserver: %d\n" "single stepping %d\n" "interrupts intr_tid %d gs_non_busy %d gs_busy %d tid_non_intr %d\n" "gdbserved addresses %d (-1 = not initialized)\n" "watchpoints %d (-1 = not initialized)\n" "vgdb-error %d\n", gdbserver_called, valgrind_single_stepping(), vgdb_interrupted_tid, interrupts_non_busy, interrupts_while_busy, interrupts_non_interruptible, nr_gdbserved_addresses, nr_watchpoints, VG_(dyn_vgdb_error)); }
/* protocol spec tells the below must be idempotent. */ static void breakpoint (Bool insert, CORE_ADDR addr) { GS_Address *g; g = VG_(HT_lookup) (gs_addresses, (UWord)HT_addr(addr)); if (insert) { /* insert a breakpoint at addr or upgrade its kind */ if (g == NULL) { add_gs_address (addr, GS_break, "m_gdbserver breakpoint insert"); } else { /* already gdbserved. Normally, it must be because of a jump. However, due to idempotent or if connection with gdb was lost (kept breaks from the previous gdb), if already existing, we just upgrade its kind. */ g->kind = GS_break; } } else { /* delete a breakpoint at addr or downgrade its kind */ if (g != NULL && g->kind == GS_break) { if (valgrind_single_stepping()) { /* keep gdbserved instrumentation while single stepping */ g->kind = GS_jump; } else { remove_gs_address (g, "m_gdbserver breakpoint remove"); } } else { dlog (1, "remove break addr %p %s\n", C2v(addr), (g == NULL ? "NULL" : (g->kind == GS_jump ? "GS_jump" : "GS_break"))); } } }
Addr valgrind_get_ignore_break_once(void) { if (valgrind_single_stepping()) return resume_pc; else return 0; }
/* Returns the reason for which gdbserver instrumentation is needed */ static VgVgdb VG_(gdbserver_instrumentation_needed) (VexGuestExtents* vge) { GS_Address* g; int e; if (!gdbserver_called) return Vg_VgdbNo; if (valgrind_single_stepping()) { dlog(2, "gdbserver_instrumentation_needed due to single stepping\n"); return Vg_VgdbYes; } if (VG_(clo_vgdb) == Vg_VgdbYes && VG_(HT_count_nodes) (gs_addresses) == 0) return Vg_VgdbNo; /* We assume we do not have a huge nr of breakpoints. Otherwise, we need something more efficient e.g. a sorted list of breakpoints or associate extents to it or ... */ VG_(HT_ResetIter) (gs_addresses); while ((g = VG_(HT_Next) (gs_addresses))) { for (e = 0; e < vge->n_used; e++) { if (g->addr >= HT_addr(vge->base[e]) && g->addr < HT_addr(vge->base[e]) + vge->len[e]) { dlog(2, "gdbserver_instrumentation_needed %p %s reason %s\n", C2v(g->addr), sym(g->addr, /* is_code */ True), (g->kind == GS_jump ? "GS_jump" : "GS_break")); return Vg_VgdbYes; } } } if (VG_(clo_vgdb) == Vg_VgdbFull) { dlog(4, "gdbserver_instrumentation_needed" " due to VG_(clo_vgdb) == Vg_VgdbFull\n"); return Vg_VgdbFull; } return Vg_VgdbNo; }
void VG_(helperc_CallDebugger) ( HWord iaddr ) { GS_Address* g; // For Vg_VgdbFull, after a fork, we might have calls to this helper // while gdbserver is not yet initialized. if (!gdbserver_called) return; if (valgrind_single_stepping() || ((g = VG_(HT_lookup) (gs_addresses, (UWord)HT_addr(iaddr))) && (g->kind == GS_break))) { if (iaddr == HT_addr(ignore_this_break_once)) { dlog(1, "ignoring ignore_this_break_once %s\n", sym(ignore_this_break_once, /* is_code */ True)); ignore_this_break_once = 0; } else { call_gdbserver (VG_(get_running_tid)(), break_reason); } } }
/* If reason is init_reason, creates the connection resources (e.g. the FIFOs) to allow a gdb connection to be detected by polling using remote_desc_activity. Otherwise (other reasons): If connection with gdb not yet opened, opens the connection with gdb. reads gdb remote protocol packets and executes the requested commands. */ static void call_gdbserver ( ThreadId tid , CallReason reason) { ThreadState* tst = VG_(get_ThreadState)(tid); int stepping; Addr saved_pc; dlog(1, "entering call_gdbserver %s ... pid %d tid %d status %s " "sched_jmpbuf_valid %d\n", ppCallReason (reason), VG_(getpid) (), tid, VG_(name_of_ThreadStatus)(tst->status), tst->sched_jmpbuf_valid); /* If we are about to die, then just run server_main() once to get the resume reply out and return immediately because most of the state of this tid and process is about to be torn down. */ if (reason == exit_reason) { server_main(); return; } vg_assert(VG_(is_valid_tid)(tid)); saved_pc = VG_(get_IP) (tid); if (gdbserver_exited) { dlog(0, "call_gdbserver called when gdbserver_exited %d\n", gdbserver_exited); return; } if (gdbserver_called == 0) { vg_assert (gs_addresses == NULL); vg_assert (gs_watches == NULL); gs_addresses = VG_(HT_construct)( "gdbserved_addresses" ); gs_watches = VG_(newXA)(gs_alloc, "gdbserved_watches", gs_free, sizeof(GS_Watch*)); VG_(atfork)(NULL, NULL, gdbserver_cleanup_in_child_after_fork); } vg_assert (gs_addresses != NULL); vg_assert (gs_watches != NULL); gdbserver_called++; /* call gdbserver_init if this is the first call to gdbserver. */ if (gdbserver_called == 1) gdbserver_init(); if (reason == init_reason || gdbserver_called == 1) remote_open(VG_(clo_vgdb_prefix)); /* if the call reason is to initialize, then return control to valgrind. After this initialization, gdbserver will be called again either if there is an error detected by valgrind or if vgdb sends data to the valgrind process. */ if (reason == init_reason) { return; } stepping = valgrind_single_stepping(); server_main(); ignore_this_break_once = valgrind_get_ignore_break_once(); if (ignore_this_break_once) dlog(1, "!!! will ignore_this_break_once %s\n", sym(ignore_this_break_once, /* is_code */ True)); if (valgrind_single_stepping()) { /* we are single stepping. If we were not stepping on entry, then invalidate the current program counter so as to properly do single step. In case the program counter was changed by gdb, this will also invalidate the target address we will jump to. */ if (!stepping && tid != 0) { invalidate_current_ip (tid, "m_gdbserver single step"); } } else { /* We are not single stepping. If we were stepping on entry, then clear the gdbserved addresses. This will cause all these gdbserved blocks to be invalidated so that they can be re-translated without being gdbserved. */ if (stepping) clear_gdbserved_addresses(/* clear only jumps */ True); } /* can't do sanity check at beginning. At least the stack check is not yet possible. */ if (gdbserver_called > 1) VG_(sanity_check_general) (/* force_expensive */ False); /* If the PC has been changed by gdb, then we VG_MINIMAL_LONGJMP to the scheduler to execute the block of the new PC. Otherwise we just return to continue executing the current block. */ if (VG_(get_IP) (tid) != saved_pc) { dlog(1, "tid %d %s PC changed from %s to %s\n", tid, VG_(name_of_ThreadStatus) (tst->status), sym(saved_pc, /* is_code */ True), sym(VG_(get_IP) (tid), /* is_code */ True)); if (tst->status == VgTs_Yielding) { SysRes sres; VG_(memset)(&sres, 0, sizeof(SysRes)); VG_(acquire_BigLock)(tid, "gdbsrv VG_MINIMAL_LONGJMP"); } if (tst->sched_jmpbuf_valid) { /* resume scheduler */ VG_MINIMAL_LONGJMP(tst->sched_jmpbuf); } /* else continue to run */ } /* continue to run */ }
void VG_(helperc_invalidate_if_not_gdbserved) ( Addr addr ) { if (valgrind_single_stepping()) invalidate_if_jump_not_yet_gdbserved (addr, "gdbserver target jump (runtime)"); }
/* When a block is instrumented for gdbserver, single step and breaks will be obeyed in this block. However, if a jump to another block is executed while single_stepping is active, we must ensure that this block is also instrumented. For this, when a block is instrumented for gdbserver while single_stepping, the target of all the Jump instructions in this block will be checked to verify if the block is already instrumented for gdbserver. The below will ensure that if not already instrumented for gdbserver, the target block translation containing addr will be invalidated. The list of gdbserved Addr will also be kept so that translations can be dropped automatically by gdbserver when going out of single step mode. Call the below at translation time if the jump target is a constant. Otherwise, rather use VG_(add_stmt_call_invalidate_if_not_gdbserved). To instrument the target exit statement, you can call VG_(add_stmt_call_invalidate_exit_target_if_not_gdbserved) rather than check the kind of target exit. */ static void VG_(invalidate_if_not_gdbserved) (Addr addr) { if (valgrind_single_stepping()) invalidate_if_jump_not_yet_gdbserved (addr, "gdbserver target jump (instrument)"); }
/* handle_gdb_valgrind_command handles the provided mon string command. If command is recognised, return 1 else return 0. Note that in case of ambiguous command, 1 is returned. *sink_wanted_at_return is modified if one of the commands 'v.set *_output' is handled. */ static int handle_gdb_valgrind_command (char* mon, OutputSink* sink_wanted_at_return) { UWord ret = 0; char s[strlen(mon)+1]; /* copy for strtok_r */ char* wcmd; HChar* ssaveptr; const char* endptr; int kwdid; int int_value; vg_assert (initial_valgrind_sink_saved); strcpy (s, mon); wcmd = strtok_r (s, " ", &ssaveptr); /* NB: if possible, avoid introducing a new command below which starts with the same 3 first letters as an already existing command. This ensures a shorter abbreviation for the user. */ switch (VG_(keyword_id) ("help v.set v.info v.wait v.kill v.translate" " v.do", wcmd, kwd_report_duplicated_matches)) { case -2: ret = 1; break; case -1: break; case 0: /* help */ ret = 1; wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd == NULL) { int_value = 0; } else { switch (VG_(keyword_id) ("debug", wcmd, kwd_report_all)) { case -2: int_value = 0; break; case -1: int_value = 0; break; case 0: int_value = 1; break; default: tl_assert (0); } } VG_(gdb_printf) ( "general valgrind monitor commands:\n" " help [debug] : monitor command help. With debug: + debugging commands\n" " v.wait [<ms>] : sleep <ms> (default 0) then continue\n" " v.info all_errors : show all errors found so far\n" " v.info last_error : show last error found\n" " v.info n_errs_found : show the nr of errors found so far\n" " v.info open_fds : show open file descriptors (only if --track-fds=yes)\n" " v.kill : kill the Valgrind process\n" " v.set gdb_output : set valgrind output to gdb\n" " v.set log_output : set valgrind output to log\n" " v.set mixed_output : set valgrind output to log, interactive output to gdb\n" " v.set merge-recursive-frames <num> : merge recursive calls in max <num> frames\n" " v.set vgdb-error <errornr> : debug me at error >= <errornr> \n"); if (int_value) { VG_(gdb_printf) ( "debugging valgrind internals monitor commands:\n" " v.do expensive_sanity_check_general : do an expensive sanity check now\n" " v.info gdbserver_status : show gdbserver status\n" " v.info memory [aspacemgr] : show valgrind heap memory stats\n" " (with aspacemgr arg, also shows valgrind segments on log ouput)\n" " v.info exectxt : show stacktraces and stats of all execontexts\n" " v.info scheduler : show valgrind thread state and stacktrace\n" " v.set debuglog <level> : set valgrind debug log level to <level>\n" " v.translate <addr> [<traceflags>] : debug translation of <addr> with <traceflags>\n" " (default traceflags 0b00100000 : show after instrumentation)\n" " An additional flag 0b100000000 allows to show gdbserver instrumentation\n"); } break; case 1: /* v.set */ ret = 1; wcmd = strtok_r (NULL, " ", &ssaveptr); switch (kwdid = VG_(keyword_id) ("vgdb-error debuglog merge-recursive-frames" " gdb_output log_output mixed_output", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: /* vgdb-error */ case 1: /* debuglog */ case 2: /* merge-recursive-frames */ wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd == NULL) { int_value = 0; endptr = "empty"; /* to report an error below */ } else { HChar *the_end; int_value = strtol (wcmd, &the_end, 10); endptr = the_end; } if (*endptr != '\0') { VG_(gdb_printf) ("missing or malformed integer value\n"); } else if (kwdid == 0) { VG_(gdb_printf) ("vgdb-error value changed from %d to %d\n", VG_(dyn_vgdb_error), int_value); VG_(dyn_vgdb_error) = int_value; } else if (kwdid == 1) { VG_(gdb_printf) ("debuglog value changed from %d to %d\n", VG_(debugLog_getLevel)(), int_value); VG_(debugLog_startup) (int_value, "gdbsrv"); } else if (kwdid == 2) { VG_(gdb_printf) ("merge-recursive-frames value changed from %d to %d\n", VG_(clo_merge_recursive_frames), int_value); VG_(clo_merge_recursive_frames) = int_value; } else { vg_assert (0); } break; case 3: /* gdb_output */ (*sink_wanted_at_return).fd = -2; command_output_to_log = False; VG_(gdb_printf) ("valgrind output will go to gdb\n"); break; case 4: /* log_output */ (*sink_wanted_at_return).fd = initial_valgrind_sink.fd; command_output_to_log = True; VG_(gdb_printf) ("valgrind output will go to log\n"); break; case 5: /* mixed output */ (*sink_wanted_at_return).fd = initial_valgrind_sink.fd; command_output_to_log = False; VG_(gdb_printf) ("valgrind output will go to log, interactive output will go to gdb\n"); break; default: vg_assert (0); } break; case 2: /* v.info */ { ret = 1; wcmd = strtok_r (NULL, " ", &ssaveptr); switch (kwdid = VG_(keyword_id) ("all_errors n_errs_found last_error gdbserver_status memory" " scheduler open_fds exectxt", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: // all_errors // A verbosity of minimum 2 is needed to show the errors. VG_(show_all_errors)(/* verbosity */ 2, /* xml */ False); break; case 1: // n_errs_found VG_(gdb_printf) ("n_errs_found %d n_errs_shown %d (vgdb-error %d)\n", VG_(get_n_errs_found) (), VG_(get_n_errs_shown) (), VG_(dyn_vgdb_error)); break; case 2: // last_error VG_(show_last_error)(); break; case 3: // gdbserver_status VG_(gdbserver_status_output)(); break; case 4: /* memory */ VG_(print_all_arena_stats) (); if (VG_(clo_profile_heap)) VG_(print_arena_cc_analysis) (); wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd != NULL) { switch (VG_(keyword_id) ("aspacemgr", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: VG_(am_show_nsegments) (0, "gdbserver v.info memory aspacemgr"); break; default: tl_assert (0); } } ret = 1; break; case 5: /* scheduler */ VG_(show_sched_status) (); ret = 1; break; case 6: /* open_fds */ if (VG_(clo_track_fds)) VG_(show_open_fds) (""); else VG_(gdb_printf) ("Valgrind must be started with --track-fds=yes" " to show open fds\n"); ret = 1; break; case 7: /* exectxt */ VG_(print_ExeContext_stats) (True /* with_stacktraces */); ret = 1; break; default: vg_assert(0); } break; } case 3: /* v.wait */ wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd != NULL) { int_value = strtol (wcmd, NULL, 10); VG_(gdb_printf) ("gdbserver: continuing in %d ms ...\n", int_value); VG_(poll)(NULL, 0, int_value); } VG_(gdb_printf) ("gdbserver: continuing after wait ...\n"); ret = 1; break; case 4: /* v.kill */ kill_request ("monitor command request to kill this process\n"); break; case 5: { /* v.translate */ Addr address; SizeT verbosity = 0x20; ret = 1; VG_(strtok_get_address_and_size) (&address, &verbosity, &ssaveptr); if (address != (Addr) 0 || verbosity != 0) { /* we need to force the output to log for the translation trace, as low level VEX tracing cannot be redirected to gdb. */ int saved_command_output_to_log = command_output_to_log; int saved_fd = VG_(log_output_sink).fd; Bool single_stepping_on_entry = valgrind_single_stepping(); int vex_verbosity = verbosity & 0xff; VG_(log_output_sink).fd = initial_valgrind_sink.fd; if ((verbosity & 0x100) && !single_stepping_on_entry) { valgrind_set_single_stepping(True); // to force gdbserver instrumentation. } # if defined(VGA_arm) // on arm, we need to (potentially) convert this address // to the thumb form. address = thumb_pc (address); # endif VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debugging*/, address, /*debugging*/True, (Int) vex_verbosity, /*bbs_done*/0, /*allow redir?*/True); if ((verbosity & 0x100) && !single_stepping_on_entry) { valgrind_set_single_stepping(False); // reset single stepping. } command_output_to_log = saved_command_output_to_log; VG_(log_output_sink).fd = saved_fd; } break; } case 6: /* v.do */ ret = 1; wcmd = strtok_r (NULL, " ", &ssaveptr); switch (VG_(keyword_id) ("expensive_sanity_check_general", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: { /* expensive_sanity_check_general */ // Temporarily bump up sanity level to check e.g. the malloc arenas. const Int save_clo_sanity_level = VG_(clo_sanity_level); if (VG_(clo_sanity_level) < 4) VG_(clo_sanity_level) = 4; VG_(sanity_check_general) (/* force_expensive */ True); VG_(clo_sanity_level) = save_clo_sanity_level; break; } default: tl_assert (0); } break; default: vg_assert (0); } return ret; }
/* handle_gdb_valgrind_command handles the provided mon string command. If command is recognised, return 1 else return 0. Note that in case of ambiguous command, 1 is returned. *sink_wanted_at_return is modified if one of the commands 'v.set *_output' is handled. */ static int handle_gdb_valgrind_command (char *mon, OutputSink *sink_wanted_at_return) { UWord ret = 0; char s[strlen(mon)+1]; /* copy for strtok_r */ char *wcmd; HChar *ssaveptr; const char *endptr; int kwdid; int int_value; vg_assert (initial_valgrind_sink_saved); strcpy (s, mon); wcmd = strtok_r (s, " ", &ssaveptr); /* NB: if possible, avoid introducing a new command below which starts with the same 3 first letters as an already existing command. This ensures a shorter abbreviation for the user. */ switch (VG_(keyword_id) ("help v.set v.info v.wait v.kill v.translate" " v.do", wcmd, kwd_report_duplicated_matches)) { case -2: ret = 1; break; case -1: break; case 0: /* help */ ret = 1; wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd == NULL) { int_value = 0; } else { switch (VG_(keyword_id) ("debug", wcmd, kwd_report_all)) { case -2: int_value = 0; break; case -1: int_value = 0; break; case 0: int_value = 1; break; default: vg_assert (0); } } VG_(gdb_printf) ( "general valgrind monitor commands:\n" " help [debug] : monitor command help. With debug: + debugging commands\n" " v.wait [<ms>] : sleep <ms> (default 0) then continue\n" " v.info all_errors : show all errors found so far\n" " v.info last_error : show last error found\n" " v.info location <addr> : show information about location <addr>\n" " v.info n_errs_found [msg] : show the nr of errors found so far and the given msg\n" " v.info open_fds : show open file descriptors (only if --track-fds=yes)\n" " v.kill : kill the Valgrind process\n" " v.set gdb_output : set valgrind output to gdb\n" " v.set log_output : set valgrind output to log\n" " v.set mixed_output : set valgrind output to log, interactive output to gdb\n" " v.set merge-recursive-frames <num> : merge recursive calls in max <num> frames\n" " v.set vgdb-error <errornr> : debug me at error >= <errornr> \n"); if (int_value) { VG_(gdb_printf) ( "debugging valgrind internals monitor commands:\n" " v.do expensive_sanity_check_general : do an expensive sanity check now\n" " v.info gdbserver_status : show gdbserver status\n" " v.info memory [aspacemgr] : show valgrind heap memory stats\n" " (with aspacemgr arg, also shows valgrind segments on log ouput)\n" " v.info exectxt : show stacktraces and stats of all execontexts\n" " v.info scheduler : show valgrind thread state and stacktrace\n" " v.info stats : show various valgrind and tool stats\n" " v.info unwind <addr> [<len>] : show unwind debug info for <addr> .. <addr+len>\n" " v.set debuglog <level> : set valgrind debug log level to <level>\n" " v.set hostvisibility [yes*|no] : (en/dis)ables access by gdb/gdbserver to\n" " Valgrind internal host status/memory\n" " v.translate <addr> [<traceflags>] : debug translation of <addr> with <traceflags>\n" " (default traceflags 0b00100000 : show after instrumentation)\n" " An additional flag 0b100000000 allows to show gdbserver instrumentation\n"); } break; case 1: /* v.set */ ret = 1; wcmd = strtok_r (NULL, " ", &ssaveptr); switch (kwdid = VG_(keyword_id) ("vgdb-error debuglog merge-recursive-frames" " gdb_output log_output mixed_output hostvisibility", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: /* vgdb-error */ case 1: /* debuglog */ case 2: /* merge-recursive-frames */ wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd == NULL) { int_value = 0; endptr = "empty"; /* to report an error below */ } else { HChar *the_end; int_value = strtol (wcmd, &the_end, 10); endptr = the_end; } if (*endptr != '\0') { VG_(gdb_printf) ("missing or malformed integer value\n"); } else if (kwdid == 0) { VG_(printf) ("vgdb-error value changed from %d to %d\n", VG_(dyn_vgdb_error), int_value); VG_(dyn_vgdb_error) = int_value; } else if (kwdid == 1) { VG_(printf) ("debuglog value changed from %d to %d\n", VG_(debugLog_getLevel)(), int_value); VG_(debugLog_startup) (int_value, "gdbsrv"); } else if (kwdid == 2) { VG_(printf) ("merge-recursive-frames value changed from %d to %d\n", VG_(clo_merge_recursive_frames), int_value); VG_(clo_merge_recursive_frames) = int_value; } else { vg_assert (0); } break; case 3: /* gdb_output */ (*sink_wanted_at_return).fd = -2; command_output_to_log = False; VG_(gdb_printf) ("valgrind output will go to gdb\n"); break; case 4: /* log_output */ (*sink_wanted_at_return).fd = initial_valgrind_sink.fd; command_output_to_log = True; VG_(gdb_printf) ("valgrind output will go to log\n"); break; case 5: /* mixed output */ (*sink_wanted_at_return).fd = initial_valgrind_sink.fd; command_output_to_log = False; VG_(gdb_printf) ("valgrind output will go to log, " "interactive output will go to gdb\n"); break; case 6: /* hostvisibility */ wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd != NULL) { switch (VG_(keyword_id) ("yes no", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: hostvisibility = True; break; case 1: hostvisibility = False; break; default: vg_assert (0); } } else { hostvisibility = True; } if (hostvisibility) { const DebugInfo *tooldi = VG_(find_DebugInfo) ((Addr)handle_gdb_valgrind_command); /* Normally, we should always find the tooldi. In case we do not, suggest a 'likely somewhat working' address: */ const Addr tool_text_start = tooldi ? VG_(DebugInfo_get_text_avma) (tooldi) : 0x38000000; const NSegment *toolseg = tooldi ? VG_(am_find_nsegment) (VG_(DebugInfo_get_text_avma) (tooldi)) : NULL; VG_(gdb_printf) ("Enabled access to Valgrind memory/status by GDB\n" "If not yet done, tell GDB which valgrind file(s) to use, " "typically:\n" "add-symbol-file %s %p\n", toolseg ? VG_(am_get_filename)(toolseg) : "<toolfile> <address> e.g.", (void*)tool_text_start); } else VG_(gdb_printf) ("Disabled access to Valgrind memory/status by GDB\n"); break; default: vg_assert (0); } break; case 2: /* v.info */ { ret = 1; wcmd = strtok_r (NULL, " ", &ssaveptr); switch (kwdid = VG_(keyword_id) ("all_errors n_errs_found last_error gdbserver_status memory" " scheduler stats open_fds exectxt location unwind", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: // all_errors // A verbosity of minimum 2 is needed to show the errors. VG_(show_all_errors)(/* verbosity */ 2, /* xml */ False); break; case 1: // n_errs_found VG_(printf) ("n_errs_found %d n_errs_shown %d (vgdb-error %d) %s\n", VG_(get_n_errs_found) (), VG_(get_n_errs_shown) (), VG_(dyn_vgdb_error), wordn (mon, 3)); break; case 2: // last_error VG_(show_last_error)(); break; case 3: // gdbserver_status VG_(gdbserver_status_output)(); break; case 4: /* memory */ VG_(printf) ("%'13llu bytes have already been mmap-ed ANONYMOUS.\n", VG_(am_get_anonsize_total)()); VG_(print_all_arena_stats) (); if (VG_(clo_profile_heap)) VG_(print_arena_cc_analysis) (); wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd != NULL) { switch (VG_(keyword_id) ("aspacemgr", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: VG_(am_show_nsegments) (0, "gdbserver v.info memory aspacemgr"); break; default: vg_assert (0); } } ret = 1; break; case 5: /* scheduler */ VG_(show_sched_status) (True, // host_stacktrace True, // stack_usage True); // exited_threads ret = 1; break; case 6: /* stats */ VG_(print_all_stats)(False, /* Memory stats */ True /* Tool stats */); ret = 1; break; case 7: /* open_fds */ if (VG_(clo_track_fds)) VG_(show_open_fds) (""); else VG_(gdb_printf) ("Valgrind must be started with --track-fds=yes" " to show open fds\n"); ret = 1; break; case 8: /* exectxt */ VG_(print_ExeContext_stats) (True /* with_stacktraces */); ret = 1; break; case 9: { /* location */ /* Note: we prefer 'v.info location' and not 'v.info address' as v.info address is inconsistent with the GDB (native) command 'info address' which gives the address for a symbol. GDB equivalent command of 'v.info location' is 'info symbol'. */ Addr address; SizeT dummy_sz = 0x1234; if (VG_(strtok_get_address_and_size) (&address, &dummy_sz, &ssaveptr)) { // If tool provides location information, use that. if (VG_(needs).info_location) { VG_TDICT_CALL(tool_info_location, address); } // If tool does not provide location info, use the common one. // Also use the common to compare with tool when debug log is set. if (!VG_(needs).info_location || VG_(debugLog_getLevel)() > 0 ) { AddrInfo ai; ai.tag = Addr_Undescribed; VG_(describe_addr) (address, &ai); VG_(pp_addrinfo) (address, &ai); VG_(clear_addrinfo) (&ai); } } ret = 1; break; } case 10: { /* unwind */ Addr address; SizeT sz = 1; if (VG_(strtok_get_address_and_size) (&address, &sz, &ssaveptr)) { VG_(ppUnwindInfo) (address, address + sz - 1); } ret = 1; break; } default: vg_assert(0); } break; } case 3: /* v.wait */ wcmd = strtok_r (NULL, " ", &ssaveptr); if (wcmd != NULL) { int_value = strtol (wcmd, NULL, 10); VG_(printf) ("gdbserver: continuing in %d ms ...\n", int_value); VG_(poll)(NULL, 0, int_value); } VG_(printf) ("gdbserver: continuing after wait ...\n"); ret = 1; break; case 4: /* v.kill */ kill_request ("monitor command request to kill this process\n"); break; case 5: { /* v.translate */ Addr address; SizeT verbosity = 0x20; ret = 1; if (VG_(strtok_get_address_and_size) (&address, &verbosity, &ssaveptr)) { /* we need to force the output to log for the translation trace, as low level VEX tracing cannot be redirected to gdb. */ int saved_command_output_to_log = command_output_to_log; int saved_fd = VG_(log_output_sink).fd; Bool single_stepping_on_entry = valgrind_single_stepping(); int vex_verbosity = verbosity & 0xff; VG_(log_output_sink).fd = initial_valgrind_sink.fd; if ((verbosity & 0x100) && !single_stepping_on_entry) { valgrind_set_single_stepping(True); // to force gdbserver instrumentation. } # if defined(VGA_arm) // on arm, we need to (potentially) convert this address // to the thumb form. address = thumb_pc (address); # endif VG_(translate) ( 0 /* dummy ThreadId; irrelevant due to debugging*/, address, /*debugging*/True, (Int) vex_verbosity, /*bbs_done*/0, /*allow redir?*/True); if ((verbosity & 0x100) && !single_stepping_on_entry) { valgrind_set_single_stepping(False); // reset single stepping. } command_output_to_log = saved_command_output_to_log; VG_(log_output_sink).fd = saved_fd; } break; } case 6: /* v.do */ ret = 1; wcmd = strtok_r (NULL, " ", &ssaveptr); switch (VG_(keyword_id) ("expensive_sanity_check_general", wcmd, kwd_report_all)) { case -2: case -1: break; case 0: { /* expensive_sanity_check_general */ // Temporarily bump up sanity level to check e.g. the malloc arenas. const Int save_clo_sanity_level = VG_(clo_sanity_level); if (VG_(clo_sanity_level) < 4) VG_(clo_sanity_level) = 4; VG_(sanity_check_general) (/* force_expensive */ True); VG_(clo_sanity_level) = save_clo_sanity_level; break; } default: vg_assert (0); } break; default: vg_assert (0); } return ret; }