Skip to content

Commit

Permalink
restore commands & functions as globals
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Jan 7, 2022
1 parent 67df573 commit 93f2b15
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def update_gef(argv):
sys.exit(0)

gef = None

#
# Those globals are required since the commands/functions registration happens *before* the
# initialisation of GEF
#
__registered_commands__ = []
__registered_functions__ = []

__watches__ = {}
__gef_convenience_vars_index__ = 0
__context_messages__ = []
Expand Down Expand Up @@ -204,6 +212,7 @@ def highlight_text(text):
within the specified string.
"""
global gef

if not gef.ui.highlight_table:
return text

Expand Down Expand Up @@ -4397,9 +4406,8 @@ def pane_title(): return "example:pane"

def register_external_command(obj):
"""Registering function for new GEF (sub-)command to GDB."""
global gef
cls = obj.__class__
gef.session.commands.append(cls)
__registered_commands__.append(cls)
gef.gdb.load(initial=False)
gef.gdb.doc.add_command_to_doc((cls._cmdline_, cls, None))
gef.gdb.doc.refresh()
Expand All @@ -4408,23 +4416,20 @@ def register_external_command(obj):

def register_command(cls):
"""Decorator for registering new GEF (sub-)command to GDB."""
global gef
gef.session.commands.append(cls)
__registered_commands__.append(cls)
return cls


def register_priority_command(cls):
"""Decorator for registering new command with priority, meaning that it must
loaded before the other generic commands."""
global gef
gef.session.commands.insert(0, cls)
__registered_commands__.insert(0, cls)
return cls


def register_function(cls):
"""Decorator for registering a new convenience function to GDB."""
global gef
gef.session.functions.append(cls)
__registered_functions__.append(cls)
return cls


Expand Down Expand Up @@ -10550,7 +10555,7 @@ def add_context_pane(self, pane_name, display_pane_function, pane_title_function
def load(self, initial=False):
"""Load all the commands and functions defined by GEF into GDB."""
nb_missing = 0
self.commands = [(x._cmdline_, x) for x in gef.session.commands]
self.commands = [(x._cmdline_, x) for x in __registered_commands__]

# load all of the functions
for function_class_name in gef.session.functions:
Expand Down Expand Up @@ -11378,8 +11383,6 @@ def __init__(self):
self.reset_caches()
self.remote = None
self.qemu_mode = False
self.commands = []
self.functions = []
self.aliases = []
return

Expand Down Expand Up @@ -11480,13 +11483,13 @@ def __init__(self):
self.binary = None
self.arch = GenericArchitecture() # see PR #516, will be reset by `new_objfile_handler`
self.config = GefSettingsManager()
self.ui = GefUiManager()
return

def reinitialize_managers(self):
self.memory = GefMemoryManager()
self.heap = GefHeapManager()
self.session = GefSessionManager()
self.ui = GefUiManager()
return

def setup(self):
Expand Down

0 comments on commit 93f2b15

Please sign in to comment.