X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fgdbserver%2Ftracepoint.c;h=9577ab7f1e95a0d5c3c3df1d5bcdd88b2f357752;hb=0747795c085d3b2a35da6bb474f32c58ce1b70c8;hp=c07e5256d3fe9052153941ec487ad92feffd5f56;hpb=35fd2deb6916e972248d52b1bc1d584fa9059f8f;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index c07e5256d3..9577ab7f1e 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -1,5 +1,5 @@ /* Tracepoint code for remote server for GDB. - Copyright (C) 2009-2016 Free Software Foundation, Inc. + Copyright (C) 2009-2019 Free Software Foundation, Inc. This file is part of GDB. @@ -19,17 +19,19 @@ #include "server.h" #include "tracepoint.h" #include "gdbthread.h" -#include "agent.h" -#include "rsp-low.h" +#include "common/rsp-low.h" #include #include #include -#include "gdb_sys_time.h" +#include #include #include "ax.h" #include "tdesc.h" +#define IPA_SYM_STRUCT_NAME ipa_sym_addresses +#include "common/agent.h" + #define DEFAULT_TRACE_BUFFER_SIZE 5242880 /* 5*1024*1024 */ /* This file is built for both GDBserver, and the in-process @@ -973,11 +975,6 @@ struct traceframe fields (and no data) marks the end of trace data. */ #define TRACEFRAME_EOB_MARKER_SIZE offsetof (struct traceframe, data) -/* The traceframe to be used as the source of data to send back to - GDB. A value of -1 means to get data from the live program. */ - -int current_traceframe = -1; - /* This flag is true if the trace buffer is circular, meaning that when it fills, the oldest trace frames are discarded in order to make room. */ @@ -1910,9 +1907,9 @@ find_next_tracepoint_by_number (struct tracepoint *prev_tp, int num) /* Append another action to perform when the tracepoint triggers. */ static void -add_tracepoint_action (struct tracepoint *tpoint, char *packet) +add_tracepoint_action (struct tracepoint *tpoint, const char *packet) { - char *act; + const char *act; if (*packet == 'S') { @@ -1924,7 +1921,7 @@ add_tracepoint_action (struct tracepoint *tpoint, char *packet) while (*act) { - char *act_start = act; + const char *act_start = act; struct tracepoint_action *action = NULL; switch (*act) @@ -2279,10 +2276,11 @@ static struct traceframe * find_next_traceframe_in_range (CORE_ADDR lo, CORE_ADDR hi, int inside_p, int *tfnump) { + client_state &cs = get_client_state (); struct traceframe *tframe; CORE_ADDR tfaddr; - *tfnump = current_traceframe + 1; + *tfnump = cs.current_traceframe + 1; tframe = find_traceframe (*tfnump); /* The search is not supposed to wrap around. */ if (!tframe) @@ -2312,9 +2310,10 @@ find_next_traceframe_in_range (CORE_ADDR lo, CORE_ADDR hi, int inside_p, static struct traceframe * find_next_traceframe_by_tracepoint (int num, int *tfnump) { + client_state &cs = get_client_state (); struct traceframe *tframe; - *tfnump = current_traceframe + 1; + *tfnump = cs.current_traceframe + 1; tframe = find_traceframe (*tfnump); /* The search is not supposed to wrap around. */ if (!tframe) @@ -2343,6 +2342,7 @@ find_next_traceframe_by_tracepoint (int num, int *tfnump) static void cmd_qtinit (char *packet) { + client_state &cs = get_client_state (); struct trace_state_variable *tsv, *prev, *next; /* Can't do this command without a pid attached. */ @@ -2353,7 +2353,7 @@ cmd_qtinit (char *packet) } /* Make sure we don't try to read from a trace frame. */ - current_traceframe = -1; + cs.current_traceframe = -1; stop_tracing (); @@ -2485,8 +2485,7 @@ cmd_qtdp (char *own_buf) ULONGEST addr; ULONGEST count; struct tracepoint *tpoint; - char *actparm; - char *packet = own_buf; + const char *packet = own_buf; packet += strlen ("QTDP:"); @@ -2546,9 +2545,7 @@ cmd_qtdp (char *own_buf) } else if (*packet == 'X') { - actparm = (char *) packet; - tpoint->cond = gdb_parse_agent_expr (&actparm); - packet = actparm; + tpoint->cond = gdb_parse_agent_expr (&packet); } else if (*packet == '-') break; @@ -2657,8 +2654,9 @@ cmd_qtdpsrc (char *own_buf) { ULONGEST num, addr, start, slen; struct tracepoint *tpoint; - char *packet = own_buf; - char *saved, *srctype, *src; + const char *packet = own_buf; + const char *saved; + char *srctype, *src; size_t nbytes; struct source_string *last, *newlast; @@ -2720,7 +2718,7 @@ cmd_qtdv (char *own_buf) char *varname; size_t nbytes; struct trace_state_variable *tsv; - char *packet = own_buf; + const char *packet = own_buf; packet += strlen ("QTDV:"); @@ -2748,7 +2746,7 @@ cmd_qtdv (char *own_buf) static void cmd_qtenable_disable (char *own_buf, int enable) { - char *packet = own_buf; + const char *packet = own_buf; ULONGEST num, addr; struct tracepoint *tp; @@ -2815,6 +2813,7 @@ cmd_qtenable_disable (char *own_buf, int enable) static void cmd_qtv (char *own_buf) { + client_state &cs = get_client_state (); ULONGEST num; LONGEST val = 0; int err; @@ -2823,7 +2822,7 @@ cmd_qtv (char *own_buf) packet += strlen ("qTV:"); unpack_varlen_hex (packet, &num); - if (current_traceframe >= 0) + if (cs.current_traceframe >= 0) { err = traceframe_read_tsv ((int) num, &val); if (err) @@ -2870,7 +2869,7 @@ cmd_qtro (char *own_buf) { ULONGEST start, end; struct readonly_region *roreg; - char *packet = own_buf; + const char *packet = own_buf; trace_debug ("Want to mark readonly regions"); @@ -3554,10 +3553,11 @@ cmd_qtdisconnected (char *own_buf) static void cmd_qtframe (char *own_buf) { + client_state &cs = get_client_state (); ULONGEST frame, pc, lo, hi, num; int tfnum, tpnum; struct traceframe *tframe; - char *packet = own_buf; + const char *packet = own_buf; packet += strlen ("QTFrame:"); @@ -3604,7 +3604,7 @@ cmd_qtframe (char *own_buf) if (tfnum == -1) { trace_debug ("Want to stop looking at traceframes"); - current_traceframe = -1; + cs.current_traceframe = -1; write_ok (own_buf); return; } @@ -3614,7 +3614,7 @@ cmd_qtframe (char *own_buf) if (tframe) { - current_traceframe = tfnum; + cs.current_traceframe = tfnum; sprintf (own_buf, "F%xT%x", tfnum, tframe->tpnum); } else @@ -3712,7 +3712,7 @@ cmd_qtp (char *own_buf) { ULONGEST num, addr; struct tracepoint *tpoint; - char *packet = own_buf; + const char *packet = own_buf; packet += strlen ("qTP:"); @@ -3956,17 +3956,6 @@ cmd_qtstmat (char *packet) run_inferior_command (packet, strlen (packet) + 1); } -/* Helper for gdb_agent_about_to_close. - Return non-zero if thread ENTRY is in the same process in DATA. */ - -static int -same_process_p (struct inferior_list_entry *entry, void *data) -{ - int *pid = (int *) data; - - return ptid_get_pid (entry->id) == *pid; -} - /* Sent the agent a command to close it. */ void @@ -3981,8 +3970,7 @@ gdb_agent_about_to_close (int pid) saved_thread = current_thread; /* Find any thread which belongs to process PID. */ - current_thread = (struct thread_info *) - find_inferior (&all_threads, same_process_p, &pid); + current_thread = find_any_thread_of_pid (pid); strcpy (buf, "close"); @@ -4017,7 +4005,7 @@ cmd_qtbuffer (char *own_buf) { ULONGEST offset, num, tot; unsigned char *tbp; - char *packet = own_buf; + const char *packet = own_buf; packet += strlen ("qTBuffer:"); @@ -4410,7 +4398,7 @@ tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc) wstep_link = &tinfo->while_stepping; trace_debug ("Thread %s finished a single-step for tracepoint %d at 0x%s", - target_pid_to_str (tinfo->entry.id), + target_pid_to_str (tinfo->id), wstep->tp_number, paddress (wstep->tp_address)); ctx.base.type = trap_tracepoint; @@ -4423,7 +4411,7 @@ tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc) { trace_debug ("NO TRACEPOINT %d at 0x%s FOR THREAD %s!", wstep->tp_number, paddress (wstep->tp_address), - target_pid_to_str (tinfo->entry.id)); + target_pid_to_str (tinfo->id)); /* Unlink. */ *wstep_link = wstep->next; @@ -4443,7 +4431,7 @@ tracepoint_finished_step (struct thread_info *tinfo, CORE_ADDR stop_pc) { /* The requested numbers of steps have occurred. */ trace_debug ("Thread %s done stepping for tracepoint %d at 0x%s", - target_pid_to_str (tinfo->entry.id), + target_pid_to_str (tinfo->id), wstep->tp_number, paddress (wstep->tp_address)); /* Unlink the wstep. */ @@ -4534,7 +4522,7 @@ handle_tracepoint_bkpts (struct thread_info *tinfo, CORE_ADDR stop_pc) trace_debug ("lib stopped due to full buffer."); if (ipa_stopping_tracepoint) trace_debug ("lib stopped due to tpoint"); - if (ipa_stopping_tracepoint) + if (ipa_error_tracepoint) trace_debug ("lib stopped due to error"); } @@ -4590,7 +4578,7 @@ tracepoint_was_hit (struct thread_info *tinfo, CORE_ADDR stop_pc) && tpoint->type != static_tracepoint) { trace_debug ("Thread %s at address of tracepoint %d at 0x%s", - target_pid_to_str (tinfo->entry.id), + target_pid_to_str (tinfo->id), tpoint->number, paddress (tpoint->address)); /* Test the condition if present, and collect if true. */ @@ -5311,6 +5299,7 @@ traceframe_read_mem (int tfnum, CORE_ADDR addr, static int traceframe_read_tsv (int tsvnum, LONGEST *val) { + client_state &cs = get_client_state (); int tfnum; struct traceframe *tframe; unsigned char *database, *dataptr; @@ -5320,7 +5309,7 @@ traceframe_read_tsv (int tsvnum, LONGEST *val) trace_debug ("traceframe_read_tsv"); - tfnum = current_traceframe; + tfnum = cs.current_traceframe; if (tfnum < 0) { @@ -5581,7 +5570,7 @@ force_unlock_trace_buffer (void) case, if we want to move the thread out of the jump pad, we need to single-step it until this function returns 0. */ -int +fast_tpoint_collect_result fast_tracepoint_collecting (CORE_ADDR thread_area, CORE_ADDR stop_pc, struct fast_tpoint_collect_status *status) @@ -5656,7 +5645,7 @@ fast_tracepoint_collecting (CORE_ADDR thread_area, if (tpoint == NULL) { warning ("in jump pad, but no matching tpoint?"); - return 0; + return fast_tpoint_collect_result::not_collecting; } else { @@ -5684,7 +5673,7 @@ fast_tracepoint_collecting (CORE_ADDR thread_area, if (tpoint == NULL) { warning ("in trampoline, but no matching tpoint?"); - return 0; + return fast_tpoint_collect_result::not_collecting; } else { @@ -5712,14 +5701,14 @@ fast_tracepoint_collecting (CORE_ADDR thread_area, { trace_debug ("fast_tracepoint_collecting:" " failed reading 'collecting' in the inferior"); - return 0; + return fast_tpoint_collect_result::not_collecting; } if (!ipa_collecting) { trace_debug ("fast_tracepoint_collecting: not collecting" " (and nobody is)."); - return 0; + return fast_tpoint_collect_result::not_collecting; } /* Some thread is collecting. Check which. */ @@ -5732,7 +5721,7 @@ fast_tracepoint_collecting (CORE_ADDR thread_area, { trace_debug ("fast_tracepoint_collecting: not collecting " "(another thread is)"); - return 0; + return fast_tpoint_collect_result::not_collecting; } tpoint @@ -5742,7 +5731,7 @@ fast_tracepoint_collecting (CORE_ADDR thread_area, warning ("fast_tracepoint_collecting: collecting, " "but tpoint %s not found?", paddress ((CORE_ADDR) ipa_collecting_obj.tpoint)); - return 0; + return fast_tpoint_collect_result::not_collecting; } /* The thread is within `gdb_collect', skip over the rest of @@ -5769,7 +5758,7 @@ fast_tracepoint_collecting (CORE_ADDR thread_area, fast_tracepoint_collecting, returning continue-until-break at %s", paddress (tpoint->adjusted_insn_addr)); - return 1; /* continue */ + return fast_tpoint_collect_result::before_insn; /* continue */ } else { @@ -5780,7 +5769,7 @@ fast_tracepoint_collecting, returning continue-until-break at %s", paddress (tpoint->adjusted_insn_addr), paddress (tpoint->adjusted_insn_addr_end)); - return 2; /* single-step */ + return fast_tpoint_collect_result::at_insn; /* single-step */ } } @@ -6848,7 +6837,7 @@ static int run_inferior_command (char *cmd, int len) { int err = -1; - int pid = ptid_get_pid (current_ptid); + int pid = current_ptid.pid (); trace_debug ("run_inferior_command: running: %s", cmd); @@ -7341,7 +7330,6 @@ gdb_agent_init (void) } #include -#include IP_AGENT_EXPORT_VAR char *gdb_tp_heap_buffer; IP_AGENT_EXPORT_VAR char *gdb_jump_pad_buffer; @@ -7410,12 +7398,10 @@ getauxval (unsigned long type) static LONGEST get_timestamp (void) { - struct timeval tv; + using namespace std::chrono; - if (gettimeofday (&tv, 0) != 0) - return -1; - else - return (LONGEST) tv.tv_sec * 1000000 + tv.tv_usec; + steady_clock::time_point now = steady_clock::now (); + return duration_cast (now.time_since_epoch ()).count (); } void