From 3fa6df48e8ab8cdeb98aaa1474cb7d345b5fa24a Mon Sep 17 00:00:00 2001 From: "Brian A. Ignacio" Date: Mon, 4 Jan 2021 17:07:51 +0800 Subject: [PATCH] add app offset to debug adapter (VSC-492) (#226) * 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 --- esp_debug_adapter | 2 +- i18n/en/package.i18n.json | 1 + i18n/es/package.i18n.json | 1 + i18n/zh-CN/package.i18n.json | 1 + package.json | 4 +++ package.nls.json | 1 + schema.i18n.json | 1 + .../debugAdapter/debugAdapterManager.ts | 27 +++++++++++++++++++ src/extension.ts | 19 ++++++++----- src/flash/flashModel.ts | 9 ++++--- src/flash/flashModelBuilder.ts | 12 +++++++++ 11 files changed, 67 insertions(+), 11 deletions(-) diff --git a/esp_debug_adapter b/esp_debug_adapter index 0d045bb1e..84e63ca2a 160000 --- a/esp_debug_adapter +++ b/esp_debug_adapter @@ -1 +1 @@ -Subproject commit 0d045bb1e56665346c055113579fd5d8fe4153ec +Subproject commit 84e63ca2a30ace4617495391018dcb0defe2576c diff --git a/i18n/en/package.i18n.json b/i18n/en/package.i18n.json index ba3050ffa..9f986cfae 100644 --- a/i18n/en/package.i18n.json +++ b/i18n/en/package.i18n.json @@ -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" diff --git a/i18n/es/package.i18n.json b/i18n/es/package.i18n.json index d5c11cf3f..b64c851dd 100644 --- a/i18n/es/package.i18n.json +++ b/i18n/es/package.i18n.json @@ -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" diff --git a/i18n/zh-CN/package.i18n.json b/i18n/zh-CN/package.i18n.json index 817fc16b5..2c6f62d92 100644 --- a/i18n/zh-CN/package.i18n.json +++ b/i18n/zh-CN/package.i18n.json @@ -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": "要执行的命令" diff --git a/package.json b/package.json index bb52bfe09..d0b74f1a8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/package.nls.json b/package.nls.json index 0f0439763..bb9626d1e 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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" diff --git a/schema.i18n.json b/schema.i18n.json index 4662d00cf..be2591d31 100644 --- a/schema.i18n.json +++ b/schema.i18n.json @@ -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" diff --git a/src/espIdf/debugAdapter/debugAdapterManager.ts b/src/espIdf/debugAdapter/debugAdapterManager.ts index 78c01446a..bbf47e385 100644 --- a/src/espIdf/debugAdapter/debugAdapterManager.ts +++ b/src/espIdf/debugAdapter/debugAdapterManager.ts @@ -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; @@ -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; @@ -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; @@ -117,6 +141,8 @@ export class DebugAdapterManager extends EventEmitter { this.port.toString(), "-dn", this.target, + "-a", + this.appOffset, ]; if (this.isPostMortemDebugMode) { adapterArgs.push("-pm"); @@ -211,6 +237,7 @@ export class DebugAdapterManager extends EventEmitter { if (config.target) { this.target = config.target; } + this.appOffset = config.appOffset; } public isRunning(): boolean { diff --git a/src/extension.ts b/src/extension.ts index 049477a1b..fec0a5586 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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, @@ -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(); diff --git a/src/flash/flashModel.ts b/src/flash/flashModel.ts index 645b630af..578b59639 100644 --- a/src/flash/flashModel.ts +++ b/src/flash/flashModel.ts @@ -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; diff --git a/src/flash/flashModelBuilder.ts b/src/flash/flashModelBuilder.ts index 97c6b1905..ad81d490e 100644 --- a/src/flash/flashModelBuilder.ts +++ b/src/flash/flashModelBuilder.ts @@ -26,6 +26,18 @@ export function createFlashModel( ): Promise { 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,