Skip to content

Commit

Permalink
add app offset to debug adapter (VSC-492) (#226)
Browse files Browse the repository at this point in the history
* add app offset to debug adapter

* offset as decimal debugAdapter param

* add app offset to launch json

* gdbstub core dump test

* update debug adapter with fixes

* rm parsing in adapter manager

* update dap fix cli 0 convert
  • Loading branch information
brianignacio5 authored Jan 4, 2021
1 parent 98cc4d2 commit 3fa6df4
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion esp_debug_adapter
1 change: 1 addition & 0 deletions i18n/en/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"espIdf.selectFlashMethodAndFlash.title": "Select Flash Method and Flash",
"idf.flashType.description": "Device flash method, UART or JTag",
"espIdf.launchWSServerAndMonitor.title": "Launch IDF Monitor for CoreDump / GDB-Stub Mode",
"esp_idf.appOffset.description": "Override build program start address offset (ESP32_APP_FLASH_OFF)",
"esp_idf.initGdbCommands.description": "One or more xtensa-esp32-elf-gdb commands to execute in order to setup the underlying debugger. Example: \"initGdbCommands\": [ \"target remote /dev/ttyUSB0\"]",
"esp_idf.gdbinitFile.description": "gdbinit file path for ESP-IDF Debug Adapter",
"esp_idf.debuggers.text.description": "The command to execute"
Expand Down
1 change: 1 addition & 0 deletions i18n/es/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"espIdf.selectFlashMethodAndFlash.title": "Seleccione el método Flash y Flash",
"idf.flashType.description": "Método de flash del dispositivo, UART o JTag",
"espIdf.launchWSServerAndMonitor.title": "Inicie el monitor IDF para el modo CoreDump / GDB-Stub",
"esp_idf.appOffset.description": "Sobrescribir offset de inicio de programa (ESP32_APP_FLASH_OFF)",
"esp_idf.initGdbCommands.description": "Uno o varios comandos xtensa-esp32-elf-gdb a ejecutar para iniciar el depurador. Ejemplo: \"initGdbCommands\": [ \"target remote /dev/ttyUSB0\"]",
"esp_idf.gdbinitFile.description": "ruta del archivo gdbinit para el ESP-IDF Debug Adapter",
"esp_idf.debuggers.text.description": "Comando a ejecutar"
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"espIdf.selectFlashMethodAndFlash.title": "选择闪光方法和闪光",
"idf.flashType.description": "设备闪存方法,UART或JTag",
"espIdf.launchWSServerAndMonitor.title": "为CoreDump / GDB-Stub模式启动IDF监视器",
"esp_idf.appOffset.description": "重写生成程序开始地址偏移量 (ESP32_APP_FLASH_OFF)",
"esp_idf.initGdbCommands.description": "要执行的一个或多个xtensa-esp32-elf-gdb命令,以便设置底层调试器。例子: \"initGdbCommands\": [ \"target remote /dev/ttyUSB0\"].",
"esp_idf.gdbinitFile.description": "ESP-IDF调试适配器的gdbinit文件路径",
"esp_idf.debuggers.text.description": "要执行的命令"
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@
"configurationAttributes": {
"launch": {
"properties": {
"appOffset": {
"type": "string",
"description": "%esp_idf.appOffset.description%"
},
"debugPort": {
"type": "number",
"description": "Port for ESP-IDF Debug Adapter. Default: 43474",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"espIdf.selectFlashMethodAndFlash.title": "Select Flash Method and Flash",
"idf.flashType.description": "Device flash method, UART or JTag",
"espIdf.launchWSServerAndMonitor.title": "Launch IDF Monitor for CoreDump / GDB-Stub Mode",
"esp_idf.appOffset.description": "Override build program start address offset (ESP32_APP_FLASH_OFF)",
"esp_idf.initGdbCommands.description": "One or more xtensa-esp32-elf-gdb commands to execute in order to setup the underlying debugger. Example: \"initGdbCommands\": [ \"target remote /dev/ttyUSB0\"]",
"esp_idf.gdbinitFile.description": "gdbinit file path for ESP-IDF Debug Adapter",
"esp_idf.debuggers.text.description": "The command to execute"
Expand Down
1 change: 1 addition & 0 deletions schema.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"espIdf.selectFlashMethodAndFlash.title",
"idf.flashType.description",
"espIdf.launchWSServerAndMonitor.title",
"esp_idf.appOffset.description",
"esp_idf.initGdbCommands.description",
"esp_idf.debuggers.text.description",
"esp_idf.gdbinitFile.description"
Expand Down
27 changes: 27 additions & 0 deletions src/espIdf/debugAdapter/debugAdapterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import {
} from "../../utils";
import { EOL } from "os";
import { outputFile, constants } from "fs-extra";
import { createFlashModel } from "../../flash/flashModelBuilder";

export interface IDebugAdapterConfig {
appOffset?: string;
coreDumpFile?: string;
currentWorkspace?: vscode.Uri;
debugAdapterPort?: number;
Expand All @@ -54,6 +56,7 @@ export class DebugAdapterManager extends EventEmitter {
private static instance: DebugAdapterManager;

private adapter: ChildProcess;
private appOffset: string;
private chan: Buffer;
private coreDumpFile: string;
private currentWorkspace: vscode.Uri;
Expand Down Expand Up @@ -102,6 +105,27 @@ export class DebugAdapterManager extends EventEmitter {
}
const logFile = path.join(this.currentWorkspace.fsPath, "debug") + ".log";

if (!this.appOffset) {
const serialPort = idfConf.readParameter("idf.port");
const flashBaudRate = idfConf.readParameter("idf.flashBaudRate");
const flasherArgsJsonPath = path.join(
this.currentWorkspace.fsPath,
"build",
"flasher_args.json"
);
if (!canAccessFile(flasherArgsJsonPath, constants.R_OK)) {
return reject(
new Error(`${flasherArgsJsonPath} doesn't exist. Build first.`)
);
}
const model = await createFlashModel(
flasherArgsJsonPath,
serialPort,
flashBaudRate
);
this.appOffset = model.app.address;
}

const pythonBinPath = idfConf.readParameter(
"idf.pythonBinPath"
) as string;
Expand All @@ -117,6 +141,8 @@ export class DebugAdapterManager extends EventEmitter {
this.port.toString(),
"-dn",
this.target,
"-a",
this.appOffset,
];
if (this.isPostMortemDebugMode) {
adapterArgs.push("-pm");
Expand Down Expand Up @@ -211,6 +237,7 @@ export class DebugAdapterManager extends EventEmitter {
if (config.target) {
this.target = config.target;
}
this.appOffset = config.appOffset;
}

public isRunning(): boolean {
Expand Down
19 changes: 12 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ export async function activate(context: vscode.ExtensionContext) {
}
if (launchMode === "auto" && !debugAdapterManager.isRunning()) {
const debugAdapterConfig = {
appOffset: session.configuration.appOffset,
debugAdapterPort: portToUse,
elfFile: session.configuration.elfFilePath,
env: session.configuration.env,
Expand Down Expand Up @@ -1618,13 +1619,17 @@ export async function activate(context: vscode.ExtensionContext) {
isPostMortemDebugMode: true,
elfFile: resp.prog,
} as IDebugAdapterConfig;
debugAdapterManager.configureAdapter(debugAdapterConfig);
await vscode.debug.startDebugging(undefined, {
name: "GDB Stub Debug",
type: "espidf",
request: "launch",
});
wsServer.done();
try {
debugAdapterManager.configureAdapter(debugAdapterConfig);
await vscode.debug.startDebugging(undefined, {
name: "GDB Stub Debug",
type: "espidf",
request: "launch",
});
wsServer.done();
} catch (error) {
Logger.errorNotify("Failed to launch debugger for postmortem", error);
}
})
.on("close", (resp) => {
wsServer.close();
Expand Down
9 changes: 6 additions & 3 deletions src/flash/flashModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

// tslint:disable: interface-name
export interface FlashModel {
port: string;
app: FlashSection;
baudRate: string;
mode: string;
bootloader: FlashSection;
flashSections: FlashSection[];
frequency: string;
mode: string;
partitionTable: FlashSection;
port: string;
size: string;
flashSections: FlashSection[];
}
export interface FlashSection {
address: string;
Expand Down
12 changes: 12 additions & 0 deletions src/flash/flashModelBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ export function createFlashModel(
): Promise<FlashModel> {
return readJSON(modelJsonPath).then((flashArgsJson) => {
const flashModel: FlashModel = {
app: {
address: flashArgsJson.app.offset,
binFilePath: flashArgsJson.app.file,
} as FlashSection,
bootloader: {
address: flashArgsJson.bootloader.offset,
binFilePath: flashArgsJson.bootloader.file,
} as FlashSection,
partitionTable: {
address: flashArgsJson.partition_table.offset,
binFilePath: flashArgsJson.partition_table.file,
} as FlashSection,
baudRate,
port,
size: flashArgsJson.flash_settings.flash_size,
Expand Down

0 comments on commit 3fa6df4

Please sign in to comment.