Skip to content

Commit 27dc586

Browse files
committed
Tools: Compile with debug info enabled so that tools can be debugged
Also add some documentation about how to debug tools and some ready to use vscode launch jobs
1 parent 1bdb55e commit 27dc586

File tree

5 files changed

+78
-14
lines changed

5 files changed

+78
-14
lines changed

.vscode/launch.json

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,19 @@
233233
],
234234
},
235235
{
236-
"name": "Debug SC-format arm64 [apple]",
236+
// Manually invoke "Build SCTest Debug" for your architecture before launching debug
237+
"name": "Debug SC-build [apple]",
237238
"type": "lldb",
238239
"request": "launch",
239-
"program": "${workspaceFolder}/_Build/_Tools/Darwin/SC-format",
240+
"program": "${workspaceFolder}/_Build/_Tools/Darwin/SC-build",
240241
"args": [
241242
"${workspaceFolder}",
242243
"${workspaceFolder}/Tools",
243-
"${workspaceFolder}/_Build"
244+
"${workspaceFolder}/_Build",
245+
"build",
246+
"configure",
247+
"SCTest",
248+
"Debug"
244249
],
245250
"cwd": "${workspaceRoot}",
246251
"console": "integratedTerminal",
@@ -249,14 +254,19 @@
249254
],
250255
},
251256
{
252-
"name": "Debug SC-format arm64 [linux] (lldb)",
257+
// Manually invoke "Build SCTest Debug" for your architecture before launching debug
258+
"name": "Debug SC-build [linux] (lldb)",
253259
"type": "lldb",
254260
"request": "launch",
255-
"program": "${workspaceFolder}/_Build/_Tools/Linux/SC-format",
261+
"program": "${workspaceFolder}/_Build/_Tools/Linux/SC-build",
256262
"args": [
257263
"${workspaceFolder}",
258264
"${workspaceFolder}/Tools",
259-
"${workspaceFolder}/_Build"
265+
"${workspaceFolder}/_Build",
266+
"build",
267+
"configure",
268+
"SCTest",
269+
"Debug"
260270
],
261271
"cwd": "${workspaceRoot}",
262272
"console": "integratedTerminal",
@@ -265,14 +275,19 @@
265275
],
266276
},
267277
{
268-
"name": "Debug SC-format arm64 [windows]",
278+
// Manually invoke "Build SCTest Debug" for your architecture before launching debug
279+
"name": "Debug SC-build [windows]",
269280
"type": "cppvsdbg",
270281
"request": "launch",
271-
"program": "${workspaceFolder}/_Build/_Tools/Windows/SC-format.exe",
282+
"program": "${workspaceFolder}/_Build/_Tools/Windows/SC-build.exe",
272283
"args": [
273-
"${workspaceFolder}",
284+
"${workspaceFolder}",
274285
"${workspaceFolder}/Tools",
275-
"${workspaceFolder}/_Build"
286+
"${workspaceFolder}/_Build",
287+
"build",
288+
"configure",
289+
"SCTest",
290+
"Debug"
276291
],
277292
"cwd": "${workspaceRoot}",
278293
"stopAtEntry": false,

Documentation/Pages/Build.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ Projects are generated by invoking `./SC.sh build` or `SC.bat build`.
3333
This is for example the `Tools/SC-build.cpp` file for the `SCTest` test suite and the [SCExample](@ref page_examples):
3434
\include Tools/SC-build.cpp
3535

36+
# How to Debug
37+
38+
1. Make sure to compile `SC::Build` invoking any of the `Build SCTest Debug | Release` vscode tasks for your architecture
39+
2. Launch the `Debug SC-build` for your platform from vscode
40+
41+
With any other debugger or IDE other than vscode, after 1. just debug `_Build/_Tools/Windows/SC-build.exe` (or the equivalent on other platform) with similar arguments as passed by the vscode task (replace `${workspaceFolder}` with the path where Sane C++ Libraries are located).
42+
The first argument is the path to SC Libraries, then you have the tools directory and the directory of the build outputs.
43+
As forth argument you have the name of the tool (`build` for `SC-Build`) and then any custom argument to the tool (`configure`, `SCTest` in the example below)
44+
45+
```json
46+
"name": "Debug SC-build [linux] (lldb)",
47+
"type": "lldb",
48+
"request": "launch",
49+
"program": "${workspaceFolder}/_Build/_Tools/Linux/SC-build",
50+
"args": [
51+
"${workspaceFolder}",
52+
"${workspaceFolder}/Tools",
53+
"${workspaceFolder}/_Build",
54+
"build",
55+
"configure",
56+
"SCTest",
57+
"Debug"
58+
],
59+
```
60+
3661
# Videos
3762

3863
This is the list of videos that have been recorded showing some of the internal thoughts that have been going into this library:

SC.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ if not exist "%BOOTSTRAP_EXE%" (
5050
if !build_bootstrap! equ 1 (
5151
set SRC_FILE=!SCRIPT_DIR!\Tools\ToolsBootstrap.c
5252
set OBJ_FILE=!SCRIPT_DIR!\_Build\_Tools\Windows\ToolsBootstrap.obj
53-
cl.exe /nologo /MTd /Fo"!OBJ_FILE!" /c "!SRC_FILE!" 2>&1
53+
cl.exe /nologo /MTd /Zi /Od /D_DEBUG=1 /Fo"!OBJ_FILE!" /c "!SRC_FILE!" 2>&1
5454
if !errorlevel! neq 0 (
5555
echo Failed to build ToolsBootstrap
5656
exit /b 1
5757
)
58-
link /nologo /OUT:"!BOOTSTRAP_EXE!" "!OBJ_FILE!" Shell32.lib 2>&1
58+
link /nologo /DEBUG /OUT:"!BOOTSTRAP_EXE!" "!OBJ_FILE!" Shell32.lib 2>&1
5959
if !errorlevel! neq 0 (
6060
echo Failed to link ToolsBootstrap
6161
exit /b 1

SC.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ mkdir -p "${SCRIPT_DIR}/_Build/_Tools/${PLATFORM}"
1313
if [ ! -f "$BOOTSTRAP_EXE" ] || [ "${SCRIPT_DIR}/Tools/ToolsBootstrap.c" -nt "$BOOTSTRAP_EXE" ]; then
1414
echo "ToolsBootstrap.c"
1515
if command -v cc >/dev/null 2>&1; then
16-
cc -o "$BOOTSTRAP_EXE" "${SCRIPT_DIR}/Tools/ToolsBootstrap.c" -std=c99
16+
cc -o "$BOOTSTRAP_EXE" "${SCRIPT_DIR}/Tools/ToolsBootstrap.c" -std=c99 -D_DEBUG=1 -g -ggdb -O0
1717
else
18-
gcc -o "$BOOTSTRAP_EXE" "${SCRIPT_DIR}/Tools/ToolsBootstrap.c" -std=c99
18+
gcc -o "$BOOTSTRAP_EXE" "${SCRIPT_DIR}/Tools/ToolsBootstrap.c" -std=c99 -D_DEBUG=1 -g -ggdb -O0
1919
fi
2020
if [ $? -ne 0 ]; then
2121
echo "Failed to build ToolsBootstrap"

Tools/ToolsBootstrap.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,10 @@ int compilePOSIX(CompilationInfo* ci) {
11061106
CommandLine_arg(&cmd, "-fvisibility-inlines-hidden");
11071107
CommandLine_arg(&cmd, "-fno-rtti");
11081108
CommandLine_arg(&cmd, "-fno-exceptions");
1109+
CommandLine_arg(&cmd, "-D_DEBUG=1");
1110+
CommandLine_arg(&cmd, "-g");
1111+
CommandLine_arg(&cmd, "-ggdb");
1112+
CommandLine_arg(&cmd, "-O0");
11091113
if (useClang) {
11101114
CommandLine_arg(&cmd, "-nostdinc++");
11111115
}
@@ -1137,6 +1141,10 @@ int compilePOSIX(CompilationInfo* ci) {
11371141
CommandLine_arg(&cmd, "-fvisibility-inlines-hidden");
11381142
CommandLine_arg(&cmd, "-fno-rtti");
11391143
CommandLine_arg(&cmd, "-fno-exceptions");
1144+
CommandLine_arg(&cmd, "-D_DEBUG=1");
1145+
CommandLine_arg(&cmd, "-g");
1146+
CommandLine_arg(&cmd, "-ggdb");
1147+
CommandLine_arg(&cmd, "-O0");
11401148
if (useClang) {
11411149
CommandLine_arg(&cmd, "-nostdinc++");
11421150
}
@@ -1201,10 +1209,18 @@ int linkWindows(CompilationInfo* ci) {
12011209
CommandLine cmd;
12021210
CommandLine_init(&cmd, "link");
12031211
CommandLine_arg(&cmd, "/nologo");
1212+
CommandLine_arg(&cmd, "/DEBUG");
12041213
StringBuilder sb = StringBuilder_init(256);
12051214
StringBuilder_append(&sb, "/OUT:\"");
12061215
StringBuilder_append(&sb, ci->toolExe);
12071216
StringBuilder_append(&sb, "\"");
1217+
StringBuilder_append(&sb, " /PDB:\"");
1218+
StringBuilder_append(&sb, ci->toolOutputDir);
1219+
StringBuilder_append(&sb, "/");
1220+
StringBuilder_append(&sb, ci->targetOS);
1221+
StringBuilder_append(&sb, "/SC-");
1222+
StringBuilder_append(&sb, ci->args->toolName);
1223+
StringBuilder_append(&sb,".pdb\"");
12081224
CommandLine_arg(&cmd, StringBuilder_get_buffer(&sb));
12091225
StringBuilder_destroy(&sb);
12101226
CommandLine_argQuoted(&cmd, toolsObj);
@@ -1320,7 +1336,11 @@ FileSystem_createDirectoryRecursive(ci->intermediateDir);
13201336
CommandLine_arg(&cmd, "/nologo");
13211337
CommandLine_arg(&cmd, "/I.");
13221338
CommandLine_arg(&cmd, "/std:c++14");
1339+
CommandLine_arg(&cmd, "/D_DEBUG");
1340+
CommandLine_arg(&cmd, "/Zi");
13231341
CommandLine_arg(&cmd, "/MTd");
1342+
CommandLine_arg(&cmd, "/GS");
1343+
CommandLine_arg(&cmd, "/Od");
13241344
CommandLine_arg(&cmd, "/permissive-");
13251345
CommandLine_arg(&cmd, "/EHsc");
13261346
CommandLine_arg(&cmd, "/sourceDependencies");
@@ -1361,7 +1381,11 @@ FileSystem_createDirectoryRecursive(ci->intermediateDir);
13611381
CommandLine_arg(&cmd, "/nologo");
13621382
CommandLine_arg(&cmd, "/I.");
13631383
CommandLine_arg(&cmd, "/std:c++14");
1384+
CommandLine_arg(&cmd, "/D_DEBUG");
1385+
CommandLine_arg(&cmd, "/Zi");
13641386
CommandLine_arg(&cmd, "/MTd");
1387+
CommandLine_arg(&cmd, "/GS");
1388+
CommandLine_arg(&cmd, "/Od");
13651389
CommandLine_arg(&cmd, "/permissive-");
13661390
CommandLine_arg(&cmd, "/EHsc");
13671391
CommandLine_arg(&cmd, "/sourceDependencies");

0 commit comments

Comments
 (0)