visual-studio-codeassemblygdbx86-64att

Breakpoints for assembly code in VSCode with GDB


I use xUbuntu 22.04.4 and the VSCode current version for linux (1.87.2)

I want to set the debugging of a .s assembly (AT&T) file. I created a task.json and a launch.json file and allowed breakpoints everywhere in the settings.

When I launch the debugging, it is working, but the breakpoint is not taken into account. What can I change in my task.json and launch.json files (see code below)?

launch.json

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Program",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

task.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-nostdlib",   // Ne pas utiliser la bibliothèque standard
                "-o",          // Spécifie le nom du fichier de sortie
                "${fileDirname}/${fileBasenameNoExtension}",     // Nom du fichier de sortie
                "${fileDirname}/${fileBasenameNoExtension}.s" // Chemin vers le fichier source
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": {
                "pattern": {
                  "regexp": "error"
                }
              },
            "presentation": {
                "reveal": "silent",
                "panel": "dedicated",
                "focus": true,
                "clear": true
              }
        }
    ]
}


Solution

  • I found that I missed the -g argument in the "args" key in task.json:

           "args": [
                    "-g", 
                    "-nostdlib", // ....
    

    in order to create debugging information for asm source line numbers.

    Without that, only disassembly mode would work, and setting breakpoints by address like b *0x400010 with an address copy/pasted from GDB disas output.