@@ -2670,7 +2670,7 @@ def get_os():
2670
2670
@lru_cache ()
2671
2671
def get_pid ():
2672
2672
"""Return the PID of the debuggee process."""
2673
- return gdb .selected_inferior ().pid
2673
+ return gdb .selected_inferior ().pid if not __gef_qemu_mode__ else gdb . selected_thread (). ptid [ 1 ]
2674
2674
2675
2675
2676
2676
@lru_cache ()
@@ -2752,7 +2752,7 @@ def download_file(target, use_cache=False, local_name=None):
2752
2752
gdb .execute ("remote get {0:s} {1:s}" .format (target , local_name ))
2753
2753
2754
2754
except gdb .error :
2755
- # gdb-stub compat
2755
+ # fallback memory view
2756
2756
with open (local_name , "w" ) as f :
2757
2757
if is_32bit ():
2758
2758
f .write ("00000000-ffffffff rwxp 00000000 00:00 0 {}\n " .format (get_filepath ()))
@@ -2768,7 +2768,7 @@ def download_file(target, use_cache=False, local_name=None):
2768
2768
def open_file (path , use_cache = False ):
2769
2769
"""Attempt to open the given file, if remote debugging is active, download
2770
2770
it first to the mirror in /tmp/."""
2771
- if is_remote_debug ():
2771
+ if is_remote_debug () and not __gef_qemu_mode__ :
2772
2772
lpath = download_file (path , use_cache )
2773
2773
if not lpath :
2774
2774
raise IOError ("cannot open remote path {:s}" .format (path ))
@@ -2860,7 +2860,7 @@ def get_info_sections():
2860
2860
break
2861
2861
2862
2862
try :
2863
- parts = [x . strip () for x in line .split ()]
2863
+ parts = [x for x in line .split ()]
2864
2864
addr_start , addr_end = [int (x , 16 ) for x in parts [1 ].split ("->" )]
2865
2865
off = int (parts [3 ][:- 1 ], 16 )
2866
2866
path = parts [4 ]
@@ -6323,9 +6323,17 @@ def prepare_qemu_stub(self, target):
6323
6323
else :
6324
6324
raise RuntimeError ("unsupported architecture: {}" .format (arch ))
6325
6325
6326
- ok ("Setting QEMU-stub for '{}' (memory mapping may be wrong)" .format (current_arch .arch ))
6326
+ ok ("Setting Qemu-user stub for '{}' (memory mapping may be wrong)" .format (current_arch .arch ))
6327
+ hide_context ()
6327
6328
gdb .execute ("target remote {}" .format (target ))
6328
- __gef_qemu_mode__ = True
6329
+ unhide_context ()
6330
+
6331
+ if get_pid () == 1 and "ENABLE=1" in gdb .execute ("maintenance packet Qqemu.sstepbits" , to_string = True , from_tty = False ):
6332
+ __gef_qemu_mode__ = True
6333
+ reset_all_caches ()
6334
+ info ("Note: By using Qemu mode, GEF will display the memory mapping of the Qemu process where the emulated binary resides" )
6335
+ get_process_maps ()
6336
+ gdb .execute ("context" )
6329
6337
return
6330
6338
6331
6339
0 commit comments