/* Tracepoint code for remote server for GDB.
- Copyright (C) 2009-2020 Free Software Foundation, Inc.
+ Copyright (C) 2009-2022 Free Software Foundation, Inc.
This file is part of GDB.
va_end (ap);
}
-#define trace_debug_1(level, fmt, args...) \
+#define trace_debug(fmt, args...) \
do { \
- if (level <= debug_threads) \
+ if (debug_threads) \
trace_vdebug ((fmt), ##args); \
} while (0)
#else
-#define trace_debug_1(level, fmt, args...) \
+#define trace_debug(fmt, args...) \
do { \
- if (level <= debug_threads) \
- { \
- debug_printf ((fmt), ##args); \
- debug_printf ("\n"); \
- } \
+ threads_debug_printf ((fmt), ##args); \
} while (0)
#endif
-#define trace_debug(FMT, args...) \
- trace_debug_1 (1, FMT, ##args)
-
/* Prefix exported symbols, for good citizenship. All the symbols
that need exporting are defined in this module. Note that all
these symbols must be tagged with IP_AGENT_EXPORT_*. */
if (look_up_one_symbol (symbol_list[i].name, addrp, 1) == 0)
{
- if (debug_threads)
- debug_printf ("symbol `%s' not found\n", symbol_list[i].name);
+ threads_debug_printf ("symbol `%s' not found", symbol_list[i].name);
return;
}
}
}
/* Breakpoint at "stop_tracing" in the inferior lib. */
-struct breakpoint *stop_tracing_bkpt;
+static struct breakpoint *stop_tracing_bkpt;
static int stop_tracing_handler (CORE_ADDR);
/* Breakpoint at "flush_trace_buffer" in the inferior lib. */
-struct breakpoint *flush_trace_buffer_bkpt;
+static struct breakpoint *flush_trace_buffer_bkpt;
static int flush_trace_buffer_handler (CORE_ADDR);
static void download_trace_state_variables (void);
static struct tracepoint *last_tracepoint;
-static const char *eval_result_names[] =
+static const char * const eval_result_names[] =
{
"terror:in the attic", /* this should never be reported */
"terror:empty expression",
/* Linked list of all trace state variables. */
#ifdef IN_PROCESS_AGENT
-struct trace_state_variable *alloced_trace_state_variables;
+static struct trace_state_variable *alloced_trace_state_variables;
#endif
IP_AGENT_EXPORT_VAR struct trace_state_variable *trace_state_variables;
it doesn't need to sync with itself. Define it as array anyway so
that the rest of the code base doesn't need to care for the
difference. */
-struct trace_buffer_control trace_buffer_ctrl[1];
+static trace_buffer_control trace_buffer_ctrl[1];
# define TRACE_BUFFER_CTRL_CURR 0
#endif
/* 64-bit timestamps for the trace run's start and finish, expressed
in microseconds from the Unix epoch. */
-LONGEST tracing_start_time;
-LONGEST tracing_stop_time;
+static LONGEST tracing_start_time;
+static LONGEST tracing_stop_time;
/* The (optional) user-supplied name of the user that started the run.
This is an arbitrary string, and may be NULL. */
-char *tracing_user_name;
+static char *tracing_user_name;
/* Optional user-supplied text describing the run. This is
an arbitrary string, and may be NULL. */
-char *tracing_notes;
+static char *tracing_notes;
/* Optional user-supplied text explaining a tstop command. This is an
arbitrary string, and may be NULL. */
-char *tracing_stop_note;
+static char *tracing_stop_note;
#endif
/* download_tracepoint will update global `tracepoints'
list, so it is unsafe to leave threads in jump pad. */
- stabilize_threads ();
+ target_stabilize_threads ();
/* Freeze threads. */
target_pause_all (true);
if (tp->type == fast_tracepoint || tp->type == static_tracepoint)
{
- int ret;
int offset = offsetof (struct tracepoint, enabled);
CORE_ADDR obj_addr = tp->obj_addr_on_target + offset;
- ret = prepare_to_access_memory ();
- if (ret)
- {
- trace_debug ("Failed to temporarily stop inferior threads");
- write_enn (own_buf);
- return;
- }
-
- ret = write_inferior_int8 (obj_addr, enable);
- done_accessing_memory ();
-
+ int ret = write_inferior_int8 (obj_addr, enable);
if (ret)
{
trace_debug ("Cannot write enabled flag into "
trampoline_size = 0;
/* Install the jump pad. */
- err = install_fast_tracepoint_jump_pad (tpoint->obj_addr_on_target,
- tpoint->address,
- collect,
- ipa_sym_addrs.addr_collecting,
- tpoint->orig_size,
- &jentry,
- &trampoline, &trampoline_size,
- fjump, &fjump_size,
- &tpoint->adjusted_insn_addr,
- &tpoint->adjusted_insn_addr_end,
- errbuf);
+ err = target_install_fast_tracepoint_jump_pad
+ (tpoint->obj_addr_on_target, tpoint->address, collect,
+ ipa_sym_addrs.addr_collecting, tpoint->orig_size, &jentry,
+ &trampoline, &trampoline_size, fjump, &fjump_size,
+ &tpoint->adjusted_insn_addr, &tpoint->adjusted_insn_addr_end, errbuf);
if (err)
return 1;
top level command. And, required to do here, since we're
deleting/rewriting jump pads. */
- stabilize_threads ();
+ target_stabilize_threads ();
/* Freeze threads. */
target_pause_all (true);
/* Tell IPA about the correct tdesc. */
if (write_inferior_integer (ipa_sym_addrs.addr_ipa_tdesc_idx,
target_get_ipa_tdesc_idx ()))
- error ("Error setting ipa_tdesc_idx variable in lib");
+ error ("Error setting ipa_tdesc_idx variable in lib");
}
/* Start out empty. */
if (!maybe_write_ipa_not_loaded (buf))
{
- struct thread_info *saved_thread;
-
- saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
/* Find any thread which belongs to process PID. */
- current_thread = find_any_thread_of_pid (pid);
+ switch_to_thread (find_any_thread_of_pid (pid));
strcpy (buf, "close");
run_inferior_command (buf, strlen (buf) + 1);
-
- current_thread = saved_thread;
}
}
wstep_link = &tinfo->while_stepping;
trace_debug ("Thread %s finished a single-step for tracepoint %d at 0x%s",
- target_pid_to_str (tinfo->id),
+ target_pid_to_str (tinfo->id).c_str (),
wstep->tp_number, paddress (wstep->tp_address));
ctx.base.type = trap_tracepoint;
{
trace_debug ("NO TRACEPOINT %d at 0x%s FOR THREAD %s!",
wstep->tp_number, paddress (wstep->tp_address),
- target_pid_to_str (tinfo->id));
+ target_pid_to_str (tinfo->id).c_str ());
/* Unlink. */
*wstep_link = wstep->next;
{
/* The requested numbers of steps have occurred. */
trace_debug ("Thread %s done stepping for tracepoint %d at 0x%s",
- target_pid_to_str (tinfo->id),
+ target_pid_to_str (tinfo->id).c_str (),
wstep->tp_number, paddress (wstep->tp_address));
/* Unlink the wstep. */
ipa_expr_eval_result,
paddress (ipa_error_tracepoint));
- if (debug_threads)
- {
- if (ipa_trace_buffer_is_full)
- trace_debug ("lib stopped due to full buffer.");
- if (ipa_stopping_tracepoint)
- trace_debug ("lib stopped due to tpoint");
- if (ipa_error_tracepoint)
- trace_debug ("lib stopped due to error");
- }
+ if (ipa_trace_buffer_is_full)
+ trace_debug ("lib stopped due to full buffer.");
+
+ if (ipa_stopping_tracepoint)
+ trace_debug ("lib stopped due to tpoint");
+
+ if (ipa_error_tracepoint)
+ trace_debug ("lib stopped due to error");
if (ipa_stopping_tracepoint != 0)
{
&& tpoint->type != static_tracepoint)
{
trace_debug ("Thread %s at address of tracepoint %d at 0x%s",
- target_pid_to_str (tinfo->id),
+ target_pid_to_str (tinfo->id).c_str (),
tpoint->number, paddress (tpoint->address));
/* Test the condition if present, and collect if true. */
addr.sun_family = AF_UNIX;
- strncpy (addr.sun_path, name, UNIX_PATH_MAX);
- addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
+ if (strlen (name) >= ARRAY_SIZE (addr.sun_path))
+ {
+ warning ("socket name too long for sockaddr_un::sun_path field: %s", name);
+ return -1;
+ }
+
+ strcpy (addr.sun_path, name);
result = access (name, F_OK);
if (result == 0)
{
int result, fd;
- result = xsnprintf (agent_socket_name, UNIX_PATH_MAX, "%s/gdb_ust%d",
- SOCK_DIR, getpid ());
+ result = snprintf (agent_socket_name, UNIX_PATH_MAX, "%s/gdb_ust%d",
+ SOCK_DIR, getpid ());
if (result >= UNIX_PATH_MAX)
{
trace_debug ("string overflow allocating socket name");