debugConfigurationProvider.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. import * as vscode from 'vscode';
  6. import * as os from 'os';
  7. /* see https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-vscode#attaching-settings */
  8. export interface WasmDebugConfig {
  9. type: string;
  10. name: string;
  11. request: string;
  12. program?: string;
  13. pid?: string;
  14. stopOnEntry?: boolean;
  15. waitFor?: boolean;
  16. initCommands?: string[];
  17. preRunCommands?: string[];
  18. stopCommands?: string[];
  19. exitCommands?: string[];
  20. terminateCommands?: string[];
  21. attachCommands?: string[];
  22. }
  23. export class WasmDebugConfigurationProvider
  24. implements vscode.DebugConfigurationProvider
  25. {
  26. private wasmDebugConfig: WasmDebugConfig = {
  27. type: 'wamr-debug',
  28. name: 'Attach',
  29. request: 'attach',
  30. stopOnEntry: true,
  31. attachCommands: [
  32. /* default port 1234 */
  33. 'process connect -p wasm connect://127.0.0.1:1234',
  34. ],
  35. };
  36. constructor(extensionPath: string) {
  37. this.wasmDebugConfig.initCommands = [
  38. /* Add rust formatters -> https://lldb.llvm.org/use/variable.html */
  39. `command script import ${extensionPath}/formatters/rust.py`,
  40. ];
  41. if (os.platform() === 'win32' || os.platform() === 'darwin') {
  42. this.wasmDebugConfig.initCommands.push(
  43. 'platform select remote-linux'
  44. );
  45. }
  46. }
  47. public resolveDebugConfiguration(
  48. _: vscode.WorkspaceFolder | undefined,
  49. debugConfiguration: vscode.DebugConfiguration
  50. ): vscode.ProviderResult<vscode.DebugConfiguration> {
  51. this.wasmDebugConfig = {
  52. ...this.wasmDebugConfig,
  53. ...debugConfiguration,
  54. };
  55. return this.wasmDebugConfig;
  56. }
  57. public getDebugConfig(): vscode.DebugConfiguration {
  58. return this.wasmDebugConfig;
  59. }
  60. }