@@ -3530,33 +3530,31 @@ def is_target_remote_or_extended(conn: gdb.TargetConnection | None = None) -> bo
35303530 return is_target_remote (conn ) or is_target_extended_remote (conn )
35313531
35323532
3533- def is_running_under_qemu () -> bool :
3533+ def is_running_in_qemu () -> bool :
35343534 "See https://www.qemu.org/docs/master/system/gdb.html "
35353535 if not is_target_remote ():
35363536 return False
35373537 response = gdb .execute ("maintenance packet Qqemu.sstepbits" , to_string = True , from_tty = False ) or ""
35383538 return "ENABLE=" in response
35393539
35403540
3541- def is_running_under_qemu_user () -> bool :
3542- if not is_running_under_qemu ():
3541+ def is_running_in_qemu_user () -> bool :
3542+ if not is_running_in_qemu ():
35433543 return False
35443544 response = gdb .execute ("maintenance packet qOffsets" , to_string = True , from_tty = False ) or "" # Use `qAttached`?
35453545 return "Text=" in response
35463546
35473547
3548- def is_running_under_qemu_system () -> bool :
3549- if not is_running_under_qemu ():
3548+ def is_running_in_qemu_system () -> bool :
3549+ if not is_running_in_qemu ():
35503550 return False
35513551 # Use "maintenance packet qqemu.PhyMemMode"?
35523552 response = gdb .execute ("maintenance packet qOffsets" , to_string = True , from_tty = False ) or ""
35533553 return "received: \" \" " in response
35543554
35553555
35563556def is_running_in_gdbserver () -> bool :
3557- if is_running_under_qemu ():
3558- return False
3559- return not is_running_under_qemu ()
3557+ return not is_running_in_qemu ()
35603558
35613559
35623560def is_running_in_rr () -> bool :
@@ -7447,7 +7445,7 @@ def __init__(self) -> None:
74477445 def do_invoke (self , _ : list [str ], ** kwargs : Any ) -> None :
74487446 args : argparse .Namespace = kwargs ["arguments" ]
74497447
7450- if is_running_under_qemu_system ():
7448+ if is_running_in_qemu_system ():
74517449 err ("Unsupported" )
74527450 return
74537451
@@ -11345,7 +11343,7 @@ def __repr__(self) -> str:
1134511343 def auxiliary_vector (self ) -> dict [str , int ] | None :
1134611344 if not is_alive ():
1134711345 return None
11348- if is_running_under_qemu_system ():
11346+ if is_running_in_qemu_system ():
1134911347 return None
1135011348 if not self ._auxiliary_vector :
1135111349 auxiliary_vector = {}
@@ -11493,9 +11491,9 @@ def prompt_string(self) -> str:
1149311491
1149411492 @staticmethod
1149511493 def init () -> "GefRemoteSessionManager.RemoteMode" :
11496- if is_running_under_qemu_system ():
11494+ if is_running_in_qemu_system ():
1149711495 return GefRemoteSessionManager .RemoteMode .QEMU_SYSTEM
11498- if is_running_under_qemu_user ():
11496+ if is_running_in_qemu_user ():
1149911497 return GefRemoteSessionManager .RemoteMode .QEMU_USER
1150011498 if is_running_in_rr ():
1150111499 return GefRemoteSessionManager .RemoteMode .RR
@@ -11619,7 +11617,7 @@ def connect(self, pid: int) -> bool:
1161911617
1162011618 def setup (self ) -> bool :
1162111619 # setup remote adequately depending on remote or qemu mode
11622- dbg (f"Setting up the { self ._mode } session " )
11620+ info (f"Setting up remote session as ' { self ._mode } ' " )
1162311621 match self .mode :
1162411622 case GefRemoteSessionManager .RemoteMode .QEMU_USER :
1162511623 self .__setup_qemu_user ()
@@ -11826,21 +11824,24 @@ def reset_caches(self) -> None:
1182611824 return
1182711825
1182811826
11827+ def target_remote_hook ():
11828+ # disable the context until the session has been fully established
11829+ gef .config ["context.enable" ] = False
11830+
11831+
1182911832def target_remote_posthook ():
11830- print (f"{ is_target_remote ()= } " )
11831- print (f"{ is_target_remote_or_extended ()= } " )
11832- print (f"{ is_target_extended_remote ()= } " )
11833- print (f"{ is_running_under_qemu ()= } " )
11834- print (f"{ is_running_under_qemu_system ()= } " )
11835- print (f"{ is_running_under_qemu_user ()= } " )
11836- print (f"{ is_running_in_gdbserver ()= } " )
11837- print (f"{ is_running_in_rr ()= } " )
1183811833 conn = gdb .selected_inferior ().connection
1183911834 if not isinstance (conn , gdb .RemoteTargetConnection ):
1184011835 raise TypeError ("Expected type gdb.RemoteTargetConnection" )
1184111836 assert is_target_remote_or_extended (conn ), "Target is not remote"
1184211837 gef .session .remote = GefRemoteSessionManager (conn )
1184311838
11839+ # re-enable context
11840+ gef .config ["context.enable" ] = True
11841+
11842+ # if here, no exception was thrown, print context
11843+ gdb .execute ("context" )
11844+
1184411845
1184511846if __name__ == "__main__" :
1184611847 if sys .version_info [0 ] == 2 :
@@ -11903,14 +11904,18 @@ def target_remote_posthook():
1190311904
1190411905 GefTmuxSetup ()
1190511906
11906- # Initialize `target *remote` post hooks
11907+ # Initialize `target *remote` pre/ post hooks
1190711908 hook = """
11908- define target hookpost -{0}
11909- pi target_remote_posthook ()
11909+ define target hook{1} -{0}
11910+ pi target_remote_{1}hook ()
1191011911 end
1191111912 """
11912- gdb .execute (hook .format ("remote" ))
11913- gdb .execute (hook .format ("extended-remote" ))
11913+ # pre-hooks
11914+ gdb .execute (hook .format ("remote" , "" ))
11915+ gdb .execute (hook .format ("extended-remote" , "" ))
11916+ # post-hooks
11917+ gdb .execute (hook .format ("remote" , "post" ))
11918+ gdb .execute (hook .format ("extended-remote" , "post" ))
1191411919
1191511920 # restore saved breakpoints (if any)
1191611921 bkp_fpath = pathlib .Path (gef .config ["gef.autosave_breakpoints_file" ]).expanduser ().absolute ()
0 commit comments