aboutsummaryrefslogtreecommitdiff
path: root/devel/gdb/files/commit-922c2fc18e4
blob: e1251e42c757765a0fe1949c688c24387e08c5c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
commit 0167735706a3328fb8d2206e6eae472e231e8695
Author: John Baldwin <jhb@FreeBSD.org>
Date:   Tue Mar 22 12:05:43 2022 -0700

    x86-nat: Use an unordered_map to store per-pid debug reg state.
    
    This replaces a manual linked list which used O(n) lookup and removal.
    
    (cherry picked from commit 922c2fc18e4de33d24b6ba3b7b6e8732209a5e69)

diff --git a/gdb/x86-nat.c b/gdb/x86-nat.c
index d0d52a00265..c1e892bf564 100644
--- gdb/x86-nat.c
+++ gdb/x86-nat.c
@@ -22,6 +22,8 @@
 #include "gdbcmd.h"
 #include "inferior.h"
 
+#include <unordered_map>
+
 /* Support for hardware watchpoints and breakpoints using the x86
    debug registers.
 
@@ -36,75 +38,20 @@
 /* Low-level function vector.  */
 struct x86_dr_low_type x86_dr_low;
 
-/* Per-process data.  We don't bind this to a per-inferior registry
-   because of targets like x86 GNU/Linux that need to keep track of
-   processes that aren't bound to any inferior (e.g., fork children,
-   checkpoints).  */
+/* Hash table storing per-process data.  We don't bind this to a
+   per-inferior registry because of targets like x86 GNU/Linux that
+   need to keep track of processes that aren't bound to any inferior
+   (e.g., fork children, checkpoints).  */
 
-struct x86_process_info
-{
-  /* Linked list.  */
-  struct x86_process_info *next;
-
-  /* The process identifier.  */
-  pid_t pid;
-
-  /* Copy of x86 hardware debug registers.  */
-  struct x86_debug_reg_state state;
-};
-
-static struct x86_process_info *x86_process_list = NULL;
-
-/* Find process data for process PID.  */
-
-static struct x86_process_info *
-x86_find_process_pid (pid_t pid)
-{
-  struct x86_process_info *proc;
-
-  for (proc = x86_process_list; proc; proc = proc->next)
-    if (proc->pid == pid)
-      return proc;
-
-  return NULL;
-}
-
-/* Add process data for process PID.  Returns newly allocated info
-   object.  */
-
-static struct x86_process_info *
-x86_add_process (pid_t pid)
-{
-  struct x86_process_info *proc = XCNEW (struct x86_process_info);
-
-  proc->pid = pid;
-  proc->next = x86_process_list;
-  x86_process_list = proc;
-
-  return proc;
-}
-
-/* Get data specific info for process PID, creating it if necessary.
-   Never returns NULL.  */
-
-static struct x86_process_info *
-x86_process_info_get (pid_t pid)
-{
-  struct x86_process_info *proc;
-
-  proc = x86_find_process_pid (pid);
-  if (proc == NULL)
-    proc = x86_add_process (pid);
-
-  return proc;
-}
+static std::unordered_map<pid_t,
+			  struct x86_debug_reg_state> x86_debug_process_state;
 
 /* Get debug registers state for process PID.  */
 
 struct x86_debug_reg_state *
 x86_debug_reg_state (pid_t pid)
 {
-  return &x86_process_info_get (pid)->state;
+  return &x86_debug_process_state[pid];
 }
 
 /* See declaration in x86-nat.h.  */
@@ -112,24 +59,7 @@ x86_debug_reg_state (pid_t pid)
 void
 x86_forget_process (pid_t pid)
 {
-  struct x86_process_info *proc, **proc_link;
-
-  proc = x86_process_list;
-  proc_link = &x86_process_list;
-
-  while (proc != NULL)
-    {
-      if (proc->pid == pid)
-	{
-	  *proc_link = proc->next;
-
-	  xfree (proc);
-	  return;
-	}
-
-      proc_link = &proc->next;
-      proc = *proc_link;
-    }
+  x86_debug_process_state.erase (pid);
 }
 
 /* Clear the reference counts and forget everything we knew about the