diff options
-rw-r--r-- | scripts/gdb/linux/utils.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py index 71ee48ceb2b2..a4a16403dc56 100644 --- a/scripts/gdb/linux/utils.py +++ b/scripts/gdb/linux/utils.py | |||
@@ -119,3 +119,38 @@ def is_target_arch(arch): | |||
119 | if target_arch is None: | 119 | if target_arch is None: |
120 | target_arch = gdb.execute("show architecture", to_string=True) | 120 | target_arch = gdb.execute("show architecture", to_string=True) |
121 | return arch in target_arch | 121 | return arch in target_arch |
122 | |||
123 | |||
124 | GDBSERVER_QEMU = 0 | ||
125 | GDBSERVER_KGDB = 1 | ||
126 | gdbserver_type = None | ||
127 | |||
128 | |||
129 | def get_gdbserver_type(): | ||
130 | def exit_handler(event): | ||
131 | global gdbserver_type | ||
132 | gdbserver_type = None | ||
133 | gdb.events.exited.disconnect(exit_handler) | ||
134 | |||
135 | def probe_qemu(): | ||
136 | try: | ||
137 | return gdb.execute("monitor info version", to_string=True) != "" | ||
138 | except: | ||
139 | return False | ||
140 | |||
141 | def probe_kgdb(): | ||
142 | try: | ||
143 | thread_info = gdb.execute("info thread 2", to_string=True) | ||
144 | return "shadowCPU0" in thread_info | ||
145 | except: | ||
146 | return False | ||
147 | |||
148 | global gdbserver_type | ||
149 | if gdbserver_type is None: | ||
150 | if probe_qemu(): | ||
151 | gdbserver_type = GDBSERVER_QEMU | ||
152 | elif probe_kgdb(): | ||
153 | gdbserver_type = GDBSERVER_KGDB | ||
154 | if not gdbserver_type is None and hasattr(gdb, 'events'): | ||
155 | gdb.events.exited.connect(exit_handler) | ||
156 | return gdbserver_type | ||