1111from commands .base_container import BaseContainer
1212from common .constants import MSG_TYPE
1313from common .context_handler import ContextHandler
14- from common .golang .constants import GO_TUNE_DEFAULT_UNPACK_DEPTH
14+ from common .golang .analysis import go_get_backtrace
15+ from common .golang .constants import GO_DEFAULT_UNPACK_DEPTH
1516from common .golang .data import GoDataBad
16- from common .golang .improvements import go_improve_backtrace
1717from common .golang .state import GoState
1818from common .golang .static import setup_go
1919from common .golang .type_getter import TypeGetter
2020from common .golang .types import ExtractInfo
21- from common .golang .util import go_calculate_bp , go_find_func , perform_go_functions
21+ from common .golang .util import go_calculate_base_pointer , go_context_analysis , go_find_func
2222from common .output_util import output_line , print_message
2323from common .settings import LLEFSettings
2424from common .state import LLEFState
@@ -103,7 +103,7 @@ def __call__(
103103
104104 if self .settings .go_support_level == "disable" :
105105 print_message (MSG_TYPE .ERROR , GO_DISABLED_MSG )
106- elif not perform_go_functions (self .settings ):
106+ elif not go_context_analysis (self .settings ):
107107 print_message (MSG_TYPE .ERROR , "The binary does not appear to be a Go binary." )
108108 else :
109109
@@ -117,9 +117,9 @@ def __call__(
117117 try :
118118 # User has typed in a numeric address
119119 address = int (address_or_name , 0 )
120- record = go_find_func (address )
121- if record is not None :
122- (entry , gofunc ) = record
120+ function_mapping = go_find_func (address )
121+ if function_mapping is not None :
122+ (entry , gofunc ) = function_mapping
123123 output_line (f"{ hex (entry )} - { gofunc .name } (file address = { hex (gofunc .file_addr )} )" )
124124 else :
125125 print_message (MSG_TYPE .ERROR , f"Could not find function containing address { hex (address )} " )
@@ -129,9 +129,9 @@ def __call__(
129129 name = address_or_name
130130
131131 success = False
132- for entry , f in LLEFState .go_state .pclntab_info .func_mapping :
133- if f . name == name :
134- output_line (f"{ hex (entry )} - { name } (file address = { hex (f .file_addr )} )" )
132+ for entry , gofunc in LLEFState .go_state .pclntab_info .func_mapping :
133+ if name in gofunc . name :
134+ output_line (f"{ hex (entry )} - { gofunc . name } (file address = { hex (gofunc .file_addr )} )" )
135135 success = True
136136 # Don't break: there are potentially multiple matches.
137137
@@ -164,8 +164,8 @@ def get_command_parser(cls) -> argparse.ArgumentParser:
164164 "-d" ,
165165 "--depth" ,
166166 type = positive_int ,
167- default = GO_TUNE_DEFAULT_UNPACK_DEPTH ,
168- help = f"Depth to unpack child types, default is { GO_TUNE_DEFAULT_UNPACK_DEPTH } " ,
167+ default = GO_DEFAULT_UNPACK_DEPTH ,
168+ help = f"Depth to unpack child types, default is { GO_DEFAULT_UNPACK_DEPTH } " ,
169169 )
170170
171171 return parser
@@ -184,7 +184,7 @@ def get_long_help() -> str:
184184 + "If not given an argument, prints a table of all known types."
185185 + os .linesep
186186 + "The depth argument specifies how deeply to follow and unpack child types. "
187- + f"It defaults to { GO_TUNE_DEFAULT_UNPACK_DEPTH } "
187+ + f"It defaults to { GO_DEFAULT_UNPACK_DEPTH } "
188188 + os .linesep
189189 + GolangGetTypeCommand .get_command_parser ().format_help ()
190190 )
@@ -214,7 +214,7 @@ def __call__(
214214
215215 if self .settings .go_support_level == "disable" :
216216 print_message (MSG_TYPE .ERROR , GO_DISABLED_MSG )
217- elif not perform_go_functions (self .settings ):
217+ elif not go_context_analysis (self .settings ):
218218 print_message (MSG_TYPE .ERROR , "The binary does not appear to be a Go binary." )
219219 elif LLEFState .go_state .moduledata_info is None :
220220 print_message (MSG_TYPE .ERROR , "No type information available in this Go binary." )
@@ -257,6 +257,14 @@ def __call__(
257257 else :
258258 print_message (MSG_TYPE .ERROR , f"Could not parse type '{ name } '" )
259259
260+ found = False
261+ for ptr , type_struct in LLEFState .go_state .moduledata_info .type_structs .items ():
262+ if name in type_struct .header .name :
263+ if found is False :
264+ print_message (MSG_TYPE .ERROR , "Did you mean:" )
265+ found = True
266+ output_line (f"{ hex (ptr )} - { type_struct .header .name } " )
267+
260268
261269class GolangUnpackTypeCommand (BaseCommand ):
262270 """Implements the 'unpack-type' subcommand"""
@@ -286,8 +294,8 @@ def get_command_parser(cls) -> argparse.ArgumentParser:
286294 "-d" ,
287295 "--depth" ,
288296 type = positive_int ,
289- default = GO_TUNE_DEFAULT_UNPACK_DEPTH ,
290- help = f"Depth to unpack child objects, default is { GO_TUNE_DEFAULT_UNPACK_DEPTH } " ,
297+ default = GO_DEFAULT_UNPACK_DEPTH ,
298+ help = f"Depth to unpack child objects, default is { GO_DEFAULT_UNPACK_DEPTH } " ,
291299 )
292300 return parser
293301
@@ -303,7 +311,7 @@ def get_long_help() -> str:
303311 + "The type can either be a string or a pointer to a type information structure."
304312 + os .linesep
305313 + "The depth argument specifies how deeply to follow and unpack child objects. "
306- + f"It defaults to { GO_TUNE_DEFAULT_UNPACK_DEPTH } "
314+ + f"It defaults to { GO_DEFAULT_UNPACK_DEPTH } "
307315 + os .linesep
308316 + GolangUnpackTypeCommand .get_command_parser ().format_help ()
309317 )
@@ -334,7 +342,7 @@ def __call__(
334342
335343 if self .settings .go_support_level == "disable" :
336344 print_message (MSG_TYPE .ERROR , GO_DISABLED_MSG )
337- elif not perform_go_functions (self .settings ):
345+ elif not go_context_analysis (self .settings ):
338346 print_message (MSG_TYPE .ERROR , "The binary does not appear to be a Go binary." )
339347 elif LLEFState .go_state .moduledata_info is None :
340348 print_message (MSG_TYPE .ERROR , "No type information available in this Go binary." )
@@ -438,22 +446,25 @@ def __call__(
438446
439447 if self .settings .go_support_level == "disable" :
440448 print_message (MSG_TYPE .ERROR , GO_DISABLED_MSG )
441- elif not perform_go_functions (self .settings ):
449+ elif not go_context_analysis (self .settings ):
442450 print_message (MSG_TYPE .ERROR , "The binary does not appear to be a Go binary." )
443451 else :
444452 # At this point, we're good to go with running the command.
445453
446- bt = go_improve_backtrace (
454+ backtrace = go_get_backtrace (
447455 exe_ctx .GetProcess (),
448456 exe_ctx .GetFrame (),
449457 self .context_handler .arch ,
450458 self .context_handler .color_settings ,
451459 depth ,
452460 )
453- if bt is not None :
454- output_line (bt )
461+ if backtrace is not None :
462+ output_line (backtrace )
455463 else :
456- print_message (MSG_TYPE .ERROR , "Go traceback failed. Try using LLDB's `bt` command." )
464+ print_message (
465+ MSG_TYPE .ERROR ,
466+ "Go traceback failed (only supported on x86 and x86_64). Try using LLDB's `bt` command." ,
467+ )
457468
458469
459470class GolangReanalyseCommand (BaseCommand ):
@@ -511,5 +522,5 @@ def __call__(
511522 else :
512523 LLEFState .go_state = GoState ()
513524 setup_go (exe_ctx .GetProcess (), exe_ctx .GetTarget (), self .settings )
514- go_calculate_bp .cache_clear ()
525+ go_calculate_base_pointer .cache_clear ()
515526 go_find_func .cache_clear ()
0 commit comments