Re: [hatari-devel] Hatari Debugger Symbols

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On 12/14/19 9:34 AM, Markus Fröschle wrote:
Am Samstag, den 14.12.2019, 02:08 +0200 schrieb Eero Tamminen:

On 12/11/19 8:37 AM, Markus Fröschle wrote:
  > Nevermind, I think I found a workaround.
  >
  > If I load my fVDI test program (the one that's supposed to trigger
the
  > fVDI bug) from floppy instead of from a GEMDOS emulated hard
drive,
  > Hatari appears to bypass auto symbol loading for that executable
and
  > retains the original fVDI symbols loaded previously.

I think symbol unloading still happens if you have
GEMDOS tracing enabled, and haven't enabled the
resident option.

Automatic symbol loading is possible only with
GEMDOS HD emulation though, as that's the only
way for Hatari to get access to the program's
symbols data.

Reading more of the my Hatari symbols.c code,
symbols should not be removed at program exit
when using "resident" option, or if they were
loaded through some other way than "symbols prg"
or auto-loading. Then, auto-loading of symbols
from a program should be skipped, if symbols are
already present.


Thank you, Eero. I don't think I need any change in Hatari, the
workaround turned out to just suit my needs perfectly.

Well, as you said, the current resident option
is pretty useless.

Attached patch changes it to an option to disable
& re-enable automatic GEMDOS HD program symbols
loading and freeing.

If you have time, could you give it a try?


With that change & option, it's much easier to
accidentally have wrong symbols for debugging &
profiling...  Especially if somebody happens to
save Hatari config with that option enabled.

Do you think that would be an issue in practice?


Since it wasn't immediately obvious (at least to me) how I could
suppress loading symbols from my "trigger" program, maybe it makes
sense to add a "debugging resident programs" recipe in the debugger
manual? This would be my suggestion, feel free to include it (as is or
modified as you see fit) in the manual, if you find it worthwile:
Thanks, that's a good idea!


Retain symbols in resident programs

When debugging resident (TSR) programs (terminated with a Ptermres()
GEMDOS call), you'll probably have a 'trigger' program that invokes
some functionality in the TSR you want to debug. Loading your 'trigger'
program from a Hatari GEMDOS emulated drive will autoload its symbols,
thus replacing the symbols of your TSR (which you are really interested
in) you loaded previously.
> You can work around this issue if you load your 'trigger' program from
another drive without GEMDOS emulation (e.g. a floppy image). This will
bypass the symbols autoload of the 'trigger' program and (provided you
have instructed the debugger to retain your TSR's symbols with the
'symbols resident' command before) allow symbolic debugging in the TSR.

Loading TSR symbols from a separate symbols file
instead of from a program file on a GEMDOS HD,
should avoid them automatically going away.

(I use that often when debugging e.g. EmuTOS.)


	- Eero
diff --git a/src/configuration.c b/src/configuration.c
index 80896164..188b1cef 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -66,7 +66,7 @@ static const struct Config_Tag configs_Debugger[] =
 	{ "nExceptionDebugMask", Int_Tag, &ConfigureParams.Debugger.nExceptionDebugMask },
 	{ "nDisasmOptions", Int_Tag, &ConfigureParams.Debugger.nDisasmOptions },
 	{ "bDisasmUAE", Bool_Tag, &ConfigureParams.Debugger.bDisasmUAE },
-	{ "bSymbolsResident", Bool_Tag, &ConfigureParams.Debugger.bSymbolsResident },
+	{ "bSymbolsAutoLoad", Bool_Tag, &ConfigureParams.Debugger.bSymbolsAutoLoad },
 	{ "bMatchAllSymbols", Bool_Tag, &ConfigureParams.Debugger.bMatchAllSymbols },
 	{ NULL , Error_Tag, NULL }
 };
@@ -663,7 +663,7 @@ void Configuration_SetDefault(void)
 	ConfigureParams.Debugger.nExceptionDebugMask = DEFAULT_EXCEPTIONS;
 	/* external one has nicer output, but isn't as complete as UAE one */
 	ConfigureParams.Debugger.bDisasmUAE = false;
-	ConfigureParams.Debugger.bSymbolsResident = false;
+	ConfigureParams.Debugger.bSymbolsAutoLoad = true;
 	ConfigureParams.Debugger.bMatchAllSymbols = false;
 	ConfigureParams.Debugger.nDisasmOptions = Disasm_GetOptions();
 
diff --git a/src/debug/symbols.c b/src/debug/symbols.c
index ef82d415..10146af1 100644
--- a/src/debug/symbols.c
+++ b/src/debug/symbols.c
@@ -390,11 +390,6 @@ static symbol_list_t* symbols_load_dri(FILE *fp, prg_section_t *sections, symtyp
 	list->symbols = symbols;
 	list->namecount = count;
 
-	/* skip verbose output when symbol loading is forced */
-	if (ConfigureParams.Debugger.bSymbolsResident) {
-		return list;
-	}
-
 	if (invalid) {
 		fprintf(stderr, "NOTE: ignored %d invalid symbols.\n", invalid);
 	}
@@ -589,11 +584,6 @@ static symbol_list_t* symbols_load_gnu(FILE *fp, prg_section_t *sections, symtyp
 	list->symbols = slots;
 	list->namecount = count;
 
-	/* skip verbose output when symbol loading is forced */
-	if (ConfigureParams.Debugger.bSymbolsResident) {
-		return list;
-	}
-
 	if (invalid) {
 		fprintf(stderr, "NOTE: ignored %d invalid symbols.\n", invalid);
 	}
@@ -673,7 +663,7 @@ static bool symbols_print_prg_info(Uint32 tabletype, Uint32 prgflags, Uint16 rel
 }
 
 /**
- * Parse program header and use symbol table format specific loader
+ * Parse program header and use symbol table format specific
  * loader function to load the symbols.
  * Return symbols list or NULL for failure.
  */
@@ -1067,8 +1057,10 @@ static symbol_list_t* Symbols_Load(const char *filename, Uint32 *offsets, Uint32
 	qsort(list->addresses, list->namecount, sizeof(symbol_t), symbols_by_address);
 	symbols_trim_addresses(list);
 
-	/* skip verbose output when symbol loading is forced */
-	if (!ConfigureParams.Debugger.bSymbolsResident) {
+	/* skip verbose output when symbols are auto-loaded */
+	if (ConfigureParams.Debugger.bSymbolsAutoLoad) {
+		fprintf(stderr, "Skipping duplicate address & symbol name checks when autoload is enabled.\n");
+	} else {
 		/* check for duplicate names */
 		if (symbols_check_names(list->names, list->namecount)) {
 			fprintf(stderr, "-> Hatari symbol expansion can match only one of the addresses for name duplicates!\n");
@@ -1461,8 +1453,8 @@ static void Symbols_Show(symbol_list_t* list, const char *sortcmd)
 /* ---------------- binary load handling ------------------ */
 
 /**
- * If symbols are set resident, load them if they aren't yet loaded,
- * otherwise remove them along with program path.
+ * If autoloading is enabled and program symbols are present,
+ * remove them along with program path.
  *
  * Called on GEMDOS reset and when program terminates
  * (unless terminated with Ptermres()).
@@ -1470,13 +1462,10 @@ static void Symbols_Show(symbol_list_t* list, const char *sortcmd)
 void Symbols_RemoveCurrentProgram(void)
 {
 	if (CurrentProgramPath) {
-		if (ConfigureParams.Debugger.bSymbolsResident) {
-			Symbols_LoadCurrentProgram();
-		}
 		free(CurrentProgramPath);
 		CurrentProgramPath = NULL;
 
-		if (CpuSymbolsList && SymbolsAreForProgram && !ConfigureParams.Debugger.bSymbolsResident) {
+		if (CpuSymbolsList && SymbolsAreForProgram && ConfigureParams.Debugger.bSymbolsAutoLoad) {
 			Symbols_Free(CpuSymbolsList);
 			fprintf(stderr, "Program exit, removing its symbols.\n");
 			CpuSymbolsList = NULL;
@@ -1486,26 +1475,15 @@ void Symbols_RemoveCurrentProgram(void)
 }
 
 /**
- * Set last opened program path and remove symbols if they
- * didn't get remove beforehand.
+ * Call Symbols_RemoveCurrentProgram() and
+ * set last opened program path.
  *
  * Called on first Fopen() after Pexec().
  */
 void Symbols_ChangeCurrentProgram(const char *path)
 {
 	if (Opt_IsAtariProgram(path)) {
-		if (ConfigureParams.Debugger.bSymbolsResident) {
-			if (CpuSymbolsList && SymbolsAreForProgram) {
-				Symbols_Free(CpuSymbolsList);
-				fprintf(stderr, "Program launch, removing previous program symbols.\n");
-				CpuSymbolsList = NULL;
-			}
-			if (CurrentProgramPath) {
-				free(CurrentProgramPath);
-			}
-		} else {
-			Symbols_RemoveCurrentProgram();
-		}
+		Symbols_RemoveCurrentProgram();
 		CurrentProgramPath = strdup(path);
 	}
 }
@@ -1518,16 +1496,19 @@ void Symbols_ShowCurrentProgramPath(FILE *fp)
 	if (CurrentProgramPath) {
 		fprintf(fp, "Current program path: %s\n", CurrentProgramPath);
 	} else {
-		fputs("No program has been loaded.\n", fp);
+		fputs("No program has been loaded (through GEMDOS HD).\n", fp);
 	}
 }
 
 /**
- * Load symbols for last opened program.
+ * Load symbols for last opened program when symbol autoloading is enabled.
  * Called when debugger is invoked.
  */
 void Symbols_LoadCurrentProgram(void)
 {
+	if (!ConfigureParams.Debugger.bSymbolsAutoLoad) {
+		return;
+	}
 	/* symbols already loaded, program path missing or previous load failed? */
 	if (CpuSymbolsList || !CurrentProgramPath || AutoLoadFailed) {
 		return;
@@ -1550,7 +1531,7 @@ void Symbols_LoadCurrentProgram(void)
 char *Symbols_MatchCommand(const char *text, int state)
 {
 	static const char* subs[] = {
-		"code", "data", "free", "match", "name", "prg", "resident"
+		"autoload", "code", "data", "free", "match", "name", "prg"
 	};
 	return DebugUI_MatchHelper(subs, ARRAY_SIZE(subs), text, state);
 }
@@ -1558,8 +1539,8 @@ char *Symbols_MatchCommand(const char *text, int state)
 const char Symbols_Description[] =
 	"<code|data|name> -- list symbols\n"
 	"\tsymbols <prg|free> -- load/free symbols\n"
-	"\tsymbols <filename> [<T offset> [<D offset> <B offset>]]\n"
-	"\tsymbols <resident|match> -- toggle symbol options\n"
+	"\t        <filename> [<T offset> [<D offset> <B offset>]]\n"
+	"\tsymbols <autoload|match> -- toggle symbol options\n"
 	"\n"
 	"\t'name' command lists the currently loaded symbols, sorted by name.\n"
 	"\t'code' and 'data' commands list them sorted by address; 'code' lists\n"
@@ -1584,9 +1565,11 @@ const char Symbols_Description[] =
 	"\tthe text (T), data (D) and BSS (B) symbols.  Typically one uses\n"
 	"\tTEXT variable, sometimes also DATA & BSS, variables for this.\n"
 	"\n"
-	"\t'resident' command toggles whether debugger will load symbols\n"
-	"\tbefore program terminates (if user hasn't entered debugger before\n"
-	"\tthis), and defers symbol freeing until another program is started.\n"
+	"\t'autoload' command toggles whether debugger will load symbols\n"
+	"\tfor currently executing (GEMDOS HD) program automatically on\n"
+	"\tentering debugger (i.e. replace earlier loaded symbols), and\n"
+	"\tfree them when program terminates.  It needs to be disabled to\n"
+	"\tdebug memory-resident programs used by other programs.\n"
 	"\n"
 	"\t'match' command toggles whether TAB completion matches all symbols,\n"
 	"\tor only symbol types that should be relevant for given command.";
@@ -1620,23 +1603,13 @@ int Symbols_Command(int nArgc, char *psArgs[])
 	}
 
 	/* toggle whether to autoload symbols on program start,
-	 * and keep them until next program start (=resident),
-	 * OR only loading them when entering the debugger and
-	 * freeing them when program terminates.
+	 * and discard them when program terminates with GEMDOS HD,
+	 * or whether they need to be loaded manually.
 	 */
-	if (strcmp(file, "resident") == 0) {
-		ConfigureParams.Debugger.bSymbolsResident = !ConfigureParams.Debugger.bSymbolsResident;
-		if (ConfigureParams.Debugger.bSymbolsResident) {
-			Symbols_LoadCurrentProgram();
-			fprintf(stderr, "Program symbols will always be loaded (with reduced warnings)\nand kept resident until next program start.\n");
-		} else {
-			fprintf(stderr, "Program symbols will be removed when program terminates.\n");
-			if (!CurrentProgramPath) {
-				/* make sure normal autoloading isn't prevented */
-				Symbols_Free(CpuSymbolsList);
-				CpuSymbolsList = NULL;
-			}
-		}
+	if (strcmp(file, "autoload") == 0) {
+		ConfigureParams.Debugger.bSymbolsAutoLoad = !ConfigureParams.Debugger.bSymbolsAutoLoad;
+		fprintf(stderr, "Program symbols auto-loading AND freeing (with GEMDOS HD) is %s\n",
+			ConfigureParams.Debugger.bSymbolsAutoLoad ? "ENABLED." : "DISABLED!");
 		return DEBUGGER_CMDDONE;
 	}
 	/* toggling whether all or only specific symbols types get TAB completed */
diff --git a/src/includes/configuration.h b/src/includes/configuration.h
index 23d6cfca..64d33510 100644
--- a/src/includes/configuration.h
+++ b/src/includes/configuration.h
@@ -35,8 +35,8 @@ typedef struct
   int nExceptionDebugMask;
   int nDisasmOptions;
   bool bDisasmUAE;
-  /* load symbols immediately on program start, and keep them after its termination */
-  bool bSymbolsResident;
+  /* load and free symbols for GEMDOS HD loaded programs automatically */
+  bool bSymbolsAutoLoad;
   /* whether to match all symbols or just types relevant for given command */
   bool bMatchAllSymbols;
 } CNF_DEBUGGER;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/