Change get_ada_task_ptid parameter type

get_ada_task_ptid currently takes a 'long' as its 'thread' parameter
type.  However, on some platforms this is actually a pointer, and
using 'long' can sometimes end up with the value being sign-extended.
This sign extension can cause problems later, if the tid is then later
used as an address again.

This patch changes the parameter type to ULONGEST and updates all the
uses.  This approach preserves sign extension on the targets where it
is apparently intended, while avoiding it on others.

Co-Authored-By: John Baldwin <jhb@FreeBSD.org>
This commit is contained in:
Tom Tromey 2021-09-17 07:46:03 -06:00
parent 96bbe3ef96
commit c80e29dba9
13 changed files with 29 additions and 29 deletions

View file

@ -600,7 +600,7 @@ ada_get_tcb_types_info (void)
static ptid_t
ptid_from_atcb_common (struct value *common_value)
{
long thread = 0;
ULONGEST thread;
CORE_ADDR lwp = 0;
struct value *ll_value;
ptid_t ptid;

View file

@ -144,7 +144,7 @@ public:
const char *extra_thread_info (struct thread_info *) override;
ptid_t get_ada_task_ptid (long lwp, long thread) override;
ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
};
static aix_thread_target aix_thread_ops;
@ -1825,7 +1825,7 @@ aix_thread_target::extra_thread_info (struct thread_info *thread)
}
ptid_t
aix_thread_target::get_ada_task_ptid (long lwp, long thread)
aix_thread_target::get_ada_task_ptid (long lwp, ULONGEST thread)
{
return ptid_t (inferior_ptid.pid (), 0, thread);
}

View file

@ -2376,7 +2376,7 @@ darwin_nat_target::pid_to_exec_file (int pid)
}
ptid_t
darwin_nat_target::get_ada_task_ptid (long lwp, long thread)
darwin_nat_target::get_ada_task_ptid (long lwp, ULONGEST thread)
{
struct inferior *inf = current_inferior ();
darwin_inferior *priv = get_darwin_inferior (inf);

View file

@ -111,7 +111,7 @@ class darwin_nat_target : public inf_child_target
bool supports_multi_process () override;
ptid_t get_ada_task_ptid (long lwp, long thread) override;
ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
private:
ptid_t wait_1 (ptid_t, struct target_waitstatus *);

View file

@ -1045,8 +1045,8 @@ fbsd_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
return;
#endif
fbsd_lwp_debug_printf ("ptid (%d, %ld, %ld)", ptid.pid (), ptid.lwp (),
ptid.tid ());
fbsd_lwp_debug_printf ("ptid (%d, %ld, %s)", ptid.pid (), ptid.lwp (),
pulongest (ptid.tid ()));
if (ptid.lwp_p ())
{
/* If ptid is a specific LWP, suspend all other LWPs in the process. */

View file

@ -102,7 +102,7 @@ public:
CORE_ADDR load_module_addr,
CORE_ADDR offset) override;
const char *extra_thread_info (struct thread_info *) override;
ptid_t get_ada_task_ptid (long lwp, long thread) override;
ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle,
int handle_len,
@ -1839,7 +1839,7 @@ thread_db_target::get_thread_local_address (ptid_t ptid,
/* Implement the to_get_ada_task_ptid target method for this target. */
ptid_t
thread_db_target::get_ada_task_ptid (long lwp, long thread)
thread_db_target::get_ada_task_ptid (long lwp, ULONGEST thread)
{
/* NPTL uses a 1:1 model, so the LWP id suffices. */
return ptid_t (inferior_ptid.pid (), lwp);

View file

@ -118,7 +118,7 @@ struct ravenscar_thread_target final : public target_ops
std::string pid_to_str (ptid_t) override;
ptid_t get_ada_task_ptid (long lwp, long thread) override;
ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
struct btrace_target_info *enable_btrace (ptid_t ptid,
const struct btrace_config *conf)
@ -682,7 +682,7 @@ ravenscar_inferior_created (inferior *inf)
}
ptid_t
ravenscar_thread_target::get_ada_task_ptid (long lwp, long thread)
ravenscar_thread_target::get_ada_task_ptid (long lwp, ULONGEST thread)
{
return ptid_t (m_base_ptid.pid (), 0, thread);
}

View file

@ -493,7 +493,7 @@ public:
const char *extra_thread_info (struct thread_info *) override;
ptid_t get_ada_task_ptid (long lwp, long thread) override;
ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle,
int handle_len,
@ -4136,7 +4136,7 @@ remote_target::static_tracepoint_markers_by_strid (const char *strid)
/* Implement the to_get_ada_task_ptid function for the remote targets. */
ptid_t
remote_target::get_ada_task_ptid (long lwp, long thread)
remote_target::get_ada_task_ptid (long lwp, ULONGEST thread)
{
return ptid_t (inferior_ptid.pid (), lwp);
}

View file

@ -88,7 +88,7 @@ public:
void resume (ptid_t, int, enum gdb_signal) override;
void mourn_inferior () override;
std::string pid_to_str (ptid_t) override;
ptid_t get_ada_task_ptid (long lwp, long thread) override;
ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
void fetch_registers (struct regcache *, int) override;
void store_registers (struct regcache *, int) override;
@ -1120,7 +1120,7 @@ info_solthreads (const char *args, int from_tty)
static int
thread_db_find_thread_from_tid (struct thread_info *thread, void *data)
{
long *tid = (long *) data;
ULONGEST *tid = (ULONGEST *) data;
if (thread->ptid.tid () == *tid)
return 1;
@ -1129,7 +1129,7 @@ thread_db_find_thread_from_tid (struct thread_info *thread, void *data)
}
ptid_t
sol_thread_target::get_ada_task_ptid (long lwp, long thread)
sol_thread_target::get_ada_task_ptid (long lwp, ULONGEST thread)
{
struct thread_info *thread_info =
iterate_over_threads (thread_db_find_thread_from_tid, &thread);

View file

@ -99,7 +99,7 @@ struct dummy_target : public target_ops
void flash_erase (ULONGEST arg0, LONGEST arg1) override;
void flash_done () override;
const struct target_desc *read_description () override;
ptid_t get_ada_task_ptid (long arg0, long arg1) override;
ptid_t get_ada_task_ptid (long arg0, ULONGEST arg1) override;
int auxv_parse (gdb_byte **arg0, gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3) override;
int search_memory (CORE_ADDR arg0, ULONGEST arg1, const gdb_byte *arg2, ULONGEST arg3, CORE_ADDR *arg4) override;
bool can_execute_reverse () override;
@ -274,7 +274,7 @@ struct debug_target : public target_ops
void flash_erase (ULONGEST arg0, LONGEST arg1) override;
void flash_done () override;
const struct target_desc *read_description () override;
ptid_t get_ada_task_ptid (long arg0, long arg1) override;
ptid_t get_ada_task_ptid (long arg0, ULONGEST arg1) override;
int auxv_parse (gdb_byte **arg0, gdb_byte *arg1, CORE_ADDR *arg2, CORE_ADDR *arg3) override;
int search_memory (CORE_ADDR arg0, ULONGEST arg1, const gdb_byte *arg2, ULONGEST arg3, CORE_ADDR *arg4) override;
bool can_execute_reverse () override;
@ -2598,19 +2598,19 @@ debug_target::read_description ()
}
ptid_t
target_ops::get_ada_task_ptid (long arg0, long arg1)
target_ops::get_ada_task_ptid (long arg0, ULONGEST arg1)
{
return this->beneath ()->get_ada_task_ptid (arg0, arg1);
}
ptid_t
dummy_target::get_ada_task_ptid (long arg0, long arg1)
dummy_target::get_ada_task_ptid (long arg0, ULONGEST arg1)
{
return default_get_ada_task_ptid (this, arg0, arg1);
}
ptid_t
debug_target::get_ada_task_ptid (long arg0, long arg1)
debug_target::get_ada_task_ptid (long arg0, ULONGEST arg1)
{
ptid_t result;
fprintf_unfiltered (gdb_stdlog, "-> %s->get_ada_task_ptid (...)\n", this->beneath ()->shortname ());
@ -2618,7 +2618,7 @@ debug_target::get_ada_task_ptid (long arg0, long arg1)
fprintf_unfiltered (gdb_stdlog, "<- %s->get_ada_task_ptid (", this->beneath ()->shortname ());
target_debug_print_long (arg0);
fputs_unfiltered (", ", gdb_stdlog);
target_debug_print_long (arg1);
target_debug_print_ULONGEST (arg1);
fputs_unfiltered (") = ", gdb_stdlog);
target_debug_print_ptid_t (result);
fputs_unfiltered ("\n", gdb_stdlog);

View file

@ -67,7 +67,7 @@ static int default_region_ok_for_hw_watchpoint (struct target_ops *,
static void default_rcmd (struct target_ops *, const char *, struct ui_file *);
static ptid_t default_get_ada_task_ptid (struct target_ops *self,
long lwp, long tid);
long lwp, ULONGEST tid);
static void default_mourn_inferior (struct target_ops *self);
@ -595,7 +595,7 @@ target_can_execute_reverse ()
}
ptid_t
target_get_ada_task_ptid (long lwp, long tid)
target_get_ada_task_ptid (long lwp, ULONGEST tid)
{
return current_inferior ()->top_target ()->get_ada_task_ptid (lwp, tid);
}
@ -1133,7 +1133,7 @@ default_terminal_info (struct target_ops *self, const char *args, int from_tty)
inferior_ptid. */
static ptid_t
default_get_ada_task_ptid (struct target_ops *self, long lwp, long tid)
default_get_ada_task_ptid (struct target_ops *self, long lwp, ULONGEST tid)
{
return ptid_t (inferior_ptid.pid (), lwp, tid);
}

View file

@ -856,7 +856,7 @@ struct target_ops
based on LWP and THREAD. These values are extracted from the
task Private_Data section of the Ada Task Control Block, and
their interpretation depends on the target. */
virtual ptid_t get_ada_task_ptid (long lwp, long thread)
virtual ptid_t get_ada_task_ptid (long lwp, ULONGEST thread)
TARGET_DEFAULT_FUNC (default_get_ada_task_ptid);
/* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
@ -2141,7 +2141,7 @@ extern bool target_can_execute_reverse ();
extern const struct target_desc *target_read_description (struct target_ops *);
extern ptid_t target_get_ada_task_ptid (long lwp, long tid);
extern ptid_t target_get_ada_task_ptid (long lwp, ULONGEST tid);
/* Main entry point for searching memory. */
extern int target_search_memory (CORE_ADDR start_addr,

View file

@ -277,7 +277,7 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target>
char *pid_to_exec_file (int pid) override;
ptid_t get_ada_task_ptid (long lwp, long thread) override;
ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override;
bool get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
@ -3082,7 +3082,7 @@ windows_nat_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
}
ptid_t
windows_nat_target::get_ada_task_ptid (long lwp, long thread)
windows_nat_target::get_ada_task_ptid (long lwp, ULONGEST thread)
{
return ptid_t (inferior_ptid.pid (), lwp, 0);
}