debugger icon indicating copy to clipboard operation
debugger copied to clipboard

[more configurable] On 'Code view' window, appends the option to shows new symbols immediately when calling 'Open Session' menu.

Open mb3h opened this issue 1 year ago • 0 comments

[Why needed] In the present, Debugger accesses symbol-files like the following. - On 'Open session' menu, it accepts file-path only and doesn't read file-text. - On 'Reload all' button, it tries to read them, but doesn't read some of them with older filetime than called 'Open Session' menu (not filetime when called its menu).

Probably, these behaviors are designed for the long debug phase without fixing code and with saving and loading session(.omds) a lot of times, maybe it is convenient in the phase acutually. But on the phase with fixing code and making symbol-files a lot of times, these are not expected, not comfortable and give frustrated. It is thought that it is better to choose behavior.

[How to patch] (1) Appending configurations. + 'ReloadSymbolFilesPerSession' + 'IgnoreSymbolsOfPrevSession' (2) In the following, separating behavior by configurations.    SymbolTable::loadSymbols() (3) Appending the signal flow. + DebuggerForm::openSession(),    DebuggerForm::systemSymbolManager()    | symbolsChanged    DisasmViewer::refresh()

--- old/DebuggerForm.cpp	2023-06-06 20:37:52.000000000 -0300
+++ src/DebuggerForm.cpp	2025-01-16 00:00:00.000000000 +0000
@@ -150,6 +150,8 @@
 DebuggerForm::DebuggerForm(QWidget* parent)
 	: QMainWindow(parent)
 	, comm(CommClient::instance())
+	, isReloadSymbolFilesPerSession(false) // false: past version behavior
+	, isIgnoreSymbolsOfPrevSession(false) // false: past version behavior
 {
 	VDPRegView = nullptr;
 	VDPStatusRegView = nullptr;
@@ -163,6 +165,23 @@
 
 	recentFiles = Settings::get().value("MainWindow/RecentFiles").toStringList();
 	updateRecentFiles();
+	// configure symbols reloading
+	struct {
+		bool *val;
+		const char *key;
+	} mapping[] = {
+		{ &isReloadSymbolFilesPerSession, "Session/ReloadSymbolFilesPerSession" },
+		{ &isIgnoreSymbolsOfPrevSession, "Session/IgnoreSymbolsOfPrevSession" },
+		{ NULL, NULL }
+	}, *p = mapping;
+	QSettings &cfg = Settings::get();
+	for (; p->val; ++p) {
+		if (cfg.contains(p->key)) {
+			*p->val = cfg.value(p->key).toBool();
+		} else if (cfg.isWritable()) {
+			cfg.setValue(p->key, *p->val);
+		}
+	}
 
 	connect(&session.symbolTable(), &SymbolTable::symbolFileChanged, this, &DebuggerForm::symbolFileChanged);
 }
@@ -1044,10 +1063,14 @@
 void DebuggerForm::openSession(const QString& file)
 {
 	fileNewSession();
-	session.open(file);
+	unsigned symConf = 0;
+	symConf |= (isReloadSymbolFilesPerSession) ? SymbolTable::LoadSymbolFiles : 0;
+	symConf |= ( isIgnoreSymbolsOfPrevSession) ? SymbolTable::IgnoreSymbolTag : 0;
+	session.open(file, symConf);
 	if (systemDisconnectAction->isEnabled()) {
 		// active connection, merge loaded breakpoints
 		reloadBreakpoints(true);
+		emit symbolsChanged();
 	}
 	// update recent
 	if (session.existsAsFile()) {
--- old/DebuggerForm.h	2023-06-02 13:54:54.000000000 -0300
+++ src/DebuggerForm.h	2025-01-16 00:00:00.000000000 +0000
@@ -161,6 +161,8 @@
 	static int counter;
 	enum {RESET = 0, SLOTS_CHECKED, PC_CHANGED, SLOTS_CHANGED} disasmStatus = RESET;
 	uint16_t disasmAddress;
+	bool isReloadSymbolFilesPerSession;
+	bool isIgnoreSymbolsOfPrevSession;
 
 	QList<CommandRef> commands;
 	void updateCustomActions();
--- old/DebugSession.cpp	2020-11-28 15:45:01.000000000 +0100
+++ src/DebugSession.cpp	2025-01-16 00:00:00.000000000 +0000
@@ -47,7 +47,7 @@
 	modified = false;
 }
 
-void DebugSession::open(const QString& file)
+void DebugSession::open(const QString& file, unsigned symConf)
 {
 	QFile f(file);
 	if (!f.open(QFile::ReadOnly | QFile::Text)) {
@@ -73,7 +73,7 @@
 				// begin tag
 				if (ses.isStartElement()) {
 					if (ses.name() == "Symbols") {
-						symTable.loadSymbols(ses);
+						symTable.loadSymbols(ses, symConf);
 					} else if (ses.name() == "Breakpoints") {
 						breaks.loadBreakpoints(ses);
 					} else {
--- old/DebugSession.h	2022-05-14 22:43:40.000000000 +0200
+++ src/DebugSession.h	2025-01-16 00:00:00.000000000 +0000
@@ -15,7 +15,7 @@
 
 	// session
 	void clear();
-	void open(const QString& file);
+	void open(const QString& file, unsigned symConf);
 	bool save();
 	bool saveAs(const QString& file);
 	bool existsAsFile() const;
--- old/SymbolTable.cpp	2023-07-17 13:55:11.000000000 +0200
+++ src/SymbolTable.cpp	2025-01-16 00:00:00.000000000 +0000
@@ -322,7 +322,8 @@
 
 	QXmlStreamReader ses;
 	ses.setDevice(&file);
-	loadSymbols(ses);
+	unsigned flags = 0; // same as past behavior
+	loadSymbols(ses, flags);
 	return true;
 }
 bool SymbolTable::readTNIASM0File(const QString& filename)
@@ -704,9 +705,10 @@
 	}
 }
 
-void SymbolTable::loadSymbols(QXmlStreamReader& xml)
+void SymbolTable::loadSymbols(QXmlStreamReader& xml, unsigned flags)
 {
-	Symbol* sym = nullptr;
+	Symbol dummy("", 0); // for ignoring
+	Symbol* sym = (LoadSymbolFiles & flags) ? &dummy : nullptr;
 	while (!xml.atEnd()) {
 		xml.readNext();
 		// exit if closing of main tag
@@ -728,12 +730,18 @@
 				} else if (ftype == "linkmap") {
 					type = LINKMAP_FILE;
 				}
-				// append file
-				appendFile(fname, type);
+				if (LoadSymbolFiles & flags) {
+					// (append file +) read file
+					bool ok = readFile(fname, type);
+					if (!ok) continue; // file cannot open, invalid format, ...
+				} else {
+					// append file
+					appendFile(fname, type);
+				}
 				// change time
 				symbolFiles.back().refreshTime.setTime_t(rtime.toUInt());
 
-			} else if (xml.name() == "Symbol") {
+			} else if (xml.name() == "Symbol" && !(IgnoreSymbolTag & flags)) {
 				// add empty symbol
 				sym = add(std::make_unique<Symbol>("", 0));
 				// get status attribute
--- old/SymbolTable.h	2023-07-17 13:44:53.000000000 +0200
+++ src/SymbolTable.h	2025-01-16 00:00:00.000000000 +0000
@@ -92,6 +92,10 @@
 		PASMO_FILE,
 		VASM_FILE
 	};
+	enum {
+		LoadSymbolFiles = 1,
+		IgnoreSymbolTag = 2,
+	};
 
 	SymbolTable();
 
@@ -103,7 +107,7 @@
 
 	// xml session file functions
 	void saveSymbols(QXmlStreamWriter& xml);
-	void loadSymbols(QXmlStreamReader& xml);
+	void loadSymbols(QXmlStreamReader& xml, unsigned flags);
 
 	// Symbol access functions
 	[[nodiscard]] Symbol* findFirstAddressSymbol(int addr, MemoryLayout* ml = nullptr);

[Related flow] 'Code view' window applies new symbols at (*2)(*3). But now 'Open Session' menu doesn't call (*2)(*3) immediately. Because the old cache 'disasmLines[]' blocks these calling at (*1) even after reloaded.

loading '.omds' ('Open session' menu etc.)
  | fileOpenSessionAction
- DebuggerForm::fileOpenSession()
  - DebuggerForm::openSession()
    | .session
    - DebugSession::open()
      | .symTable
      - SymbolTable::loadSymbols() (*)from .omds(XML)

modifying symbol-file ('.map' etc.)
  | fileWatcher
- QFileSystemWatcher::???
  | emit fileChanged

  | (SymbolTable::)this
  - SymbolTable::fileChanged()
    | emit symbolFileChanged

    | (DebuggerForm::)this
    - DebuggerForm::symbolFileChanged()
      | user request, 'Yes'
      | .session
      - DebugSession::symbolTable()
      | .symTable
      - SymbolTable:reloadFiles()
      | emit symbolFilesChanged

      | (DebuggerForm::).symManager
      - SymbolManager::refresh()

- main()
  - DebuggerForm::ctor()
    - DebuggerForm::createForm()
      | .session
      - DebugSession::symbolTable()
      - DisasmViewer::setSymbolTable()
        | .symTable

- DebuggerForm::searchGoto()
  | .disasmView
  - DisasmViewer::setCursorAddress()
    + DisasmViewer::setAddress()
      - DisasmViewer::findPosition() (*1)
        - DisasmViewer::findDisasmLine()
      - DisasmViewer::requestMemory() (*2)
        - CommMemoryRequest::ctor()
        - CommClient::instance()
        - CommClient::sendCommand()
        |
        - CommMemoryRequest::replyOk()
          - DisasmViewer::memoryUpdated() (*3)

mb3h avatar Feb 03 '25 04:02 mb3h