-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from joshua-smith-12/gdb
support GDB debugging on overlays via custom GDB build
- Loading branch information
Showing
12 changed files
with
272 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,8 @@ cmake-build-* | |
diff.txt | ||
|
||
.vs/ | ||
.vscode/ | ||
.vscode/* | ||
!.vscode/launch.json | ||
|
||
temp_asm/ | ||
asm_old/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug in melonDS", | ||
"type": "cppdbg", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/build/debug.nef", | ||
"MIMode": "gdb", | ||
"cwd": "${workspaceFolder}", | ||
"externalConsole": true, | ||
"miDebuggerServerAddress": "localhost:3333", | ||
// point this to your own gdb path... | ||
"miDebuggerPath": "/path/to/binutils-gdb/gdb/gdb", | ||
//"miDebuggerPath": "gdb-multiarch", | ||
"setupCommands": [ | ||
{ | ||
"description": "Enable pretty-printing", | ||
"text": "-enable-pretty-printing", | ||
"ignoreFailures": true | ||
}, | ||
{ | ||
"description": "Set architecture", | ||
"text": "set architecture armv5te" | ||
}, | ||
{ | ||
"description": "Enable overlays", | ||
"text": "overlay auto" | ||
}, | ||
{ | ||
"description": "Enable overlay map", | ||
"text": "overlay map build/overlay.map" | ||
} | ||
], | ||
"stopAtConnect": false, | ||
"stopAtEntry": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
option('gdb_debugging', type : 'boolean', value : false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nef_fixer_py = find_program('nef_fixer.py', native: true) | ||
overlay_mapper_py = find_program('overlay_mapper.py', native: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python3 | ||
|
||
### This tool is responsible for using `debugedit` to fix Wine paths in the debuginfo file to real filesystem paths. | ||
### VSC requires the debuginfo paths to map to real filesystem paths in order for VSC to correctly open sources during a debugging session. | ||
### (This works fine on my Linux system, but may or may not work on WSL, and will certainly not work on other systems) | ||
import subprocess | ||
import os | ||
import shutil | ||
import sys | ||
|
||
try: | ||
os.remove("sources.txt") | ||
except: | ||
pass | ||
|
||
source = sys.argv[1] | ||
dest = sys.argv[2] | ||
|
||
print(f"Copying {source} to {dest}") | ||
shutil.copyfile(source, dest) | ||
|
||
print("Retrieving source file list via debugedit") | ||
subprocess.run(["debugedit", "-l", "sources.txt", dest]) | ||
|
||
with open("sources.txt") as f: | ||
content = f.read() | ||
all_sources = content.split('\0') | ||
|
||
print("Identifying unique source directories") | ||
source_paths = [] | ||
for source in all_sources: | ||
source_parts = source.split(":") | ||
if len(source_parts) != 3: continue | ||
|
||
source_original = source_parts[0] + ":" + source_parts[1] | ||
source_original = source_original[:-2] | ||
|
||
if source_original not in source_paths: | ||
source_paths.append(source_original) | ||
|
||
print(f"Identified {len(source_paths)} unique source directories from source file list") | ||
for source in source_paths: | ||
remapped = source.replace("\\", "/")[2:] | ||
print(f"Remapping source path from {source} to {remapped} using debugedit.") | ||
subprocess.run(["debugedit", "-b", source, "-d", remapped, dest]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python3 | ||
|
||
### This tool creates a file which maps overlay section names and source file names to overlay IDs. | ||
### custom GDB build then processes this source map and uses it to identify what overlay a source file belongs to. | ||
### (This makes it a lot easier to identify which overlapping overlay is used for a given input location). | ||
import subprocess | ||
import os | ||
import shutil | ||
import sys | ||
|
||
try: | ||
os.remove("overlay.map") | ||
except: | ||
pass | ||
|
||
source = sys.argv[1] | ||
dest = sys.argv[2] | ||
|
||
# TERRIBLE but necessary to allow using the LSF file | ||
def base_path(path): | ||
splitted = path.split("_") | ||
maybe_path = "" | ||
found_dir = ".." # need to escape builddir because this sucks | ||
while len(splitted) > 1: | ||
segment = splitted[0] | ||
splitted = splitted[1:] | ||
maybe_path += segment | ||
if os.path.isdir(found_dir + "/" + maybe_path): | ||
found_dir = found_dir + "/" + maybe_path | ||
maybe_path = "" | ||
else: | ||
maybe_path += "_" | ||
maybe_path += splitted[0] | ||
return maybe_path[:-2] # remove '.o' | ||
|
||
# VERY inflexible parsing! | ||
overlays = {} | ||
sources = {} | ||
overlay_index = 0 | ||
current_overlay = None | ||
in_block = False | ||
with open(source) as f: | ||
for line in f.readlines(): | ||
if current_overlay == None and not in_block and line.strip().startswith("Overlay"): | ||
current_overlay = line.strip().replace("Overlay ", "") | ||
overlays[current_overlay] = overlay_index | ||
overlay_index += 1 | ||
elif not in_block and line.strip() == "{": | ||
in_block = True | ||
elif in_block and line.strip() == "}": | ||
in_block = False | ||
current_overlay = None | ||
elif current_overlay != None and in_block and line.strip().startswith("Object"): | ||
obj_name = base_path(line.strip().replace("Object ", "").split("/")[-1]) | ||
sources[obj_name] = current_overlay | ||
|
||
with open(dest, mode="w") as f: | ||
for ovly in overlays: | ||
f.write(f"OVERLAY {ovly}:{overlays[ovly]}\n") | ||
f.write("\n") | ||
for s in sources: | ||
f.write(f"SOURCE {s}:{sources[s]}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters