mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-16 14:19:52 +08:00
gdbserver: change 'all_processes' and 'all_threads' list type
This patch replaces the 'std::list' type of 'all_processes' and 'all_threads' with the more lightweight 'owning_intrusive_list' type. Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
@@ -20,14 +20,12 @@
|
||||
#define GDBSERVER_GDBTHREAD_H
|
||||
|
||||
#include "gdbsupport/function-view.h"
|
||||
#include "inferiors.h"
|
||||
|
||||
#include <list>
|
||||
#include "gdbsupport/owning_intrusive_list.h"
|
||||
|
||||
struct btrace_target_info;
|
||||
struct regcache;
|
||||
|
||||
struct thread_info
|
||||
struct thread_info : public intrusive_list_node<thread_info>
|
||||
{
|
||||
thread_info (ptid_t id, void *target_data)
|
||||
: id (id), target_data (target_data)
|
||||
@@ -85,7 +83,7 @@ struct thread_info
|
||||
gdb_thread_options thread_options = 0;
|
||||
};
|
||||
|
||||
extern std::list<thread_info *> all_threads;
|
||||
extern owning_intrusive_list<thread_info> all_threads;
|
||||
|
||||
void remove_thread (struct thread_info *thread);
|
||||
struct thread_info *add_thread (ptid_t ptid, void *target_data);
|
||||
|
||||
@@ -20,11 +20,12 @@
|
||||
|
||||
#include "gdbsupport/common-gdbthread.h"
|
||||
#include "gdbsupport/common-inferior.h"
|
||||
#include "gdbsupport/owning_intrusive_list.h"
|
||||
#include "gdbthread.h"
|
||||
#include "dll.h"
|
||||
|
||||
std::list<process_info *> all_processes;
|
||||
std::list<thread_info *> all_threads;
|
||||
owning_intrusive_list<process_info> all_processes;
|
||||
owning_intrusive_list<thread_info> all_threads;
|
||||
|
||||
/* The current process. */
|
||||
static process_info *current_process_;
|
||||
@@ -41,14 +42,12 @@ static std::string current_inferior_cwd;
|
||||
struct thread_info *
|
||||
add_thread (ptid_t thread_id, void *target_data)
|
||||
{
|
||||
thread_info *new_thread = new thread_info (thread_id, target_data);
|
||||
|
||||
all_threads.push_back (new_thread);
|
||||
auto &new_thread = all_threads.emplace_back (thread_id, target_data);
|
||||
|
||||
if (current_thread == NULL)
|
||||
switch_to_thread (new_thread);
|
||||
switch_to_thread (&new_thread);
|
||||
|
||||
return new_thread;
|
||||
return &new_thread;
|
||||
}
|
||||
|
||||
/* See gdbthread.h. */
|
||||
@@ -57,7 +56,7 @@ struct thread_info *
|
||||
get_first_thread (void)
|
||||
{
|
||||
if (!all_threads.empty ())
|
||||
return all_threads.front ();
|
||||
return &all_threads.front ();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@@ -89,12 +88,6 @@ find_any_thread_of_pid (int pid)
|
||||
});
|
||||
}
|
||||
|
||||
static void
|
||||
free_one_thread (thread_info *thread)
|
||||
{
|
||||
delete thread;
|
||||
}
|
||||
|
||||
void
|
||||
remove_thread (struct thread_info *thread)
|
||||
{
|
||||
@@ -102,10 +95,10 @@ remove_thread (struct thread_info *thread)
|
||||
target_disable_btrace (thread->btrace);
|
||||
|
||||
discard_queued_stop_replies (ptid_of (thread));
|
||||
all_threads.remove (thread);
|
||||
if (current_thread == thread)
|
||||
switch_to_thread (nullptr);
|
||||
free_one_thread (thread);
|
||||
|
||||
all_threads.erase (all_threads.iterator_to (*thread));
|
||||
}
|
||||
|
||||
void *
|
||||
@@ -129,7 +122,6 @@ set_thread_regcache_data (struct thread_info *thread, struct regcache *data)
|
||||
void
|
||||
clear_inferiors (void)
|
||||
{
|
||||
for_each_thread (free_one_thread);
|
||||
all_threads.clear ();
|
||||
|
||||
clear_dlls ();
|
||||
@@ -141,11 +133,7 @@ clear_inferiors (void)
|
||||
struct process_info *
|
||||
add_process (int pid, int attached)
|
||||
{
|
||||
process_info *process = new process_info (pid, attached);
|
||||
|
||||
all_processes.push_back (process);
|
||||
|
||||
return process;
|
||||
return &all_processes.emplace_back (pid, attached);
|
||||
}
|
||||
|
||||
/* Remove a process from the common process list and free the memory
|
||||
@@ -158,10 +146,10 @@ remove_process (struct process_info *process)
|
||||
clear_symbol_cache (&process->symbol_cache);
|
||||
free_all_breakpoints (process);
|
||||
gdb_assert (find_thread_process (process) == NULL);
|
||||
all_processes.remove (process);
|
||||
if (current_process () == process)
|
||||
switch_to_process (nullptr);
|
||||
delete process;
|
||||
|
||||
all_processes.erase (all_processes.iterator_to (*process));
|
||||
}
|
||||
|
||||
process_info *
|
||||
@@ -178,7 +166,7 @@ process_info *
|
||||
get_first_process (void)
|
||||
{
|
||||
if (!all_processes.empty ())
|
||||
return all_processes.front ();
|
||||
return &all_processes.front ();
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@@ -221,13 +209,14 @@ current_process (void)
|
||||
void
|
||||
for_each_process (gdb::function_view<void (process_info *)> func)
|
||||
{
|
||||
std::list<process_info *>::iterator next, cur = all_processes.begin ();
|
||||
owning_intrusive_list<process_info>::iterator next, cur
|
||||
= all_processes.begin ();
|
||||
|
||||
while (cur != all_processes.end ())
|
||||
{
|
||||
next = cur;
|
||||
next++;
|
||||
func (*cur);
|
||||
func (&*cur);
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
@@ -237,18 +226,9 @@ for_each_process (gdb::function_view<void (process_info *)> func)
|
||||
process_info *
|
||||
find_process (gdb::function_view<bool (process_info *)> func)
|
||||
{
|
||||
std::list<process_info *>::iterator next, cur = all_processes.begin ();
|
||||
|
||||
while (cur != all_processes.end ())
|
||||
{
|
||||
next = cur;
|
||||
next++;
|
||||
|
||||
if (func (*cur))
|
||||
return *cur;
|
||||
|
||||
cur = next;
|
||||
}
|
||||
for (process_info &process : all_processes)
|
||||
if (func (&process))
|
||||
return &process;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -258,18 +238,9 @@ find_process (gdb::function_view<bool (process_info *)> func)
|
||||
thread_info *
|
||||
find_thread (gdb::function_view<bool (thread_info *)> func)
|
||||
{
|
||||
std::list<thread_info *>::iterator next, cur = all_threads.begin ();
|
||||
|
||||
while (cur != all_threads.end ())
|
||||
{
|
||||
next = cur;
|
||||
next++;
|
||||
|
||||
if (func (*cur))
|
||||
return *cur;
|
||||
|
||||
cur = next;
|
||||
}
|
||||
for (thread_info &thread : all_threads)
|
||||
if (func (&thread))
|
||||
return &thread;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -300,13 +271,13 @@ find_thread (ptid_t filter, gdb::function_view<bool (thread_info *)> func)
|
||||
void
|
||||
for_each_thread (gdb::function_view<void (thread_info *)> func)
|
||||
{
|
||||
std::list<thread_info *>::iterator next, cur = all_threads.begin ();
|
||||
owning_intrusive_list<thread_info>::iterator next, cur = all_threads.begin ();
|
||||
|
||||
while (cur != all_threads.end ())
|
||||
{
|
||||
next = cur;
|
||||
next++;
|
||||
func (*cur);
|
||||
func (&*cur);
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
#define GDBSERVER_INFERIORS_H
|
||||
|
||||
#include "gdbsupport/gdb_vecs.h"
|
||||
#include "gdbsupport/owning_intrusive_list.h"
|
||||
|
||||
#include "dll.h"
|
||||
#include <list>
|
||||
|
||||
struct thread_info;
|
||||
struct regcache;
|
||||
@@ -32,7 +33,7 @@ struct raw_breakpoint;
|
||||
struct fast_tracepoint_jump;
|
||||
struct process_info_private;
|
||||
|
||||
struct process_info
|
||||
struct process_info : public intrusive_list_node<process_info>
|
||||
{
|
||||
process_info (int pid_, int attached_)
|
||||
: pid (pid_), attached (attached_)
|
||||
@@ -99,7 +100,7 @@ pid_of (const process_info *proc)
|
||||
struct process_info *current_process (void);
|
||||
struct process_info *get_thread_process (const struct thread_info *);
|
||||
|
||||
extern std::list<process_info *> all_processes;
|
||||
extern owning_intrusive_list<process_info> all_processes;
|
||||
|
||||
/* Invoke FUNC for each process. */
|
||||
|
||||
|
||||
@@ -1355,15 +1355,15 @@ handle_detach (char *own_buf)
|
||||
another process might delete the next thread in the iteration, which is
|
||||
the one saved by the safe iterator. We will never delete the currently
|
||||
iterated on thread, so standard iteration should be safe. */
|
||||
for (thread_info *thread : all_threads)
|
||||
for (thread_info &thread : all_threads)
|
||||
{
|
||||
/* Only threads that are of the process we are detaching. */
|
||||
if (thread->id.pid () != pid)
|
||||
if (thread.id.pid () != pid)
|
||||
continue;
|
||||
|
||||
/* Only threads that have a pending fork event. */
|
||||
target_waitkind kind;
|
||||
thread_info *child = target_thread_pending_child (thread, &kind);
|
||||
thread_info *child = target_thread_pending_child (&thread, &kind);
|
||||
if (child == nullptr || kind == TARGET_WAITKIND_THREAD_CLONED)
|
||||
continue;
|
||||
|
||||
@@ -1375,7 +1375,7 @@ handle_detach (char *own_buf)
|
||||
if (detach_inferior (fork_child_process) != 0)
|
||||
warning (_("Failed to detach fork child %s, child of %s"),
|
||||
target_pid_to_str (ptid_t (fork_child_pid)).c_str (),
|
||||
target_pid_to_str (thread->id).c_str ());
|
||||
target_pid_to_str (thread.id).c_str ());
|
||||
}
|
||||
|
||||
if (detach_inferior (process) != 0)
|
||||
@@ -2523,7 +2523,7 @@ static void
|
||||
handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
|
||||
{
|
||||
client_state &cs = get_client_state ();
|
||||
static std::list<thread_info *>::const_iterator thread_iter;
|
||||
static owning_intrusive_list<thread_info>::iterator thread_iter;
|
||||
|
||||
/* Reply the current thread id. */
|
||||
if (strcmp ("qC", own_buf) == 0 && !disable_packet_qC)
|
||||
@@ -2536,7 +2536,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
|
||||
else
|
||||
{
|
||||
thread_iter = all_threads.begin ();
|
||||
ptid = (*thread_iter)->id;
|
||||
ptid = thread_iter->id;
|
||||
}
|
||||
|
||||
sprintf (own_buf, "QC");
|
||||
@@ -2599,7 +2599,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
|
||||
thread_iter = all_threads.begin ();
|
||||
|
||||
*own_buf++ = 'm';
|
||||
ptid_t ptid = (*thread_iter)->id;
|
||||
ptid_t ptid = thread_iter->id;
|
||||
write_ptid (own_buf, ptid);
|
||||
thread_iter++;
|
||||
return;
|
||||
@@ -2611,7 +2611,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
|
||||
if (thread_iter != all_threads.end ())
|
||||
{
|
||||
*own_buf++ = 'm';
|
||||
ptid_t ptid = (*thread_iter)->id;
|
||||
ptid_t ptid = thread_iter->id;
|
||||
write_ptid (own_buf, ptid);
|
||||
thread_iter++;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user