Skip to content

Commit

Permalink
Allow 'View Disassembly' to enter regular expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
haneefdm committed Feb 13, 2020
1 parent b672834 commit 03bf581
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This is a pretty big release. The biggest change is to address C++ (and maybe Ru
* There were some performance enhancements done for loading the Variables window when Global or Static scopes were expanded. Noticeable when single-stepping in large executables.
* New setting `flattenAnonymous` which will flatten anonymous structs/unions. Default=false
* New setting `registerUseNaturalFormat` which will display registers either in Natural format or Hex: Default=true
* The command `View Disassembly (Function)` now supports a regular expression as input. It will try an exact match for a function name first. But, it that fails treats the input string as a regular expression, and if the input string ends with `/i` it is treated as case-insensitive. As always, if there are multiple matches, you have to pick one.

# V0.3.4

Expand Down
17 changes: 14 additions & 3 deletions src/frontend/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,26 @@ export class CortexDebugExtension {
let funcname: string = await vscode.window.showInputBox({
placeHolder: 'main',
ignoreFocusOut: true,
prompt: 'Function Name to Disassemble'
prompt: 'Function Name (exact or a regexp) to Disassemble.'
});

funcname = funcname ? funcname.trim() : null;
if (!funcname) { return ; }

const functions = this.functionSymbols.filter((s) => s.name === funcname);
let functions = this.functionSymbols.filter((s) => s.name === funcname);
if (functions.length === 0) {
let regExp = new RegExp(funcname);
if (funcname.endsWith('/i')) {
// This is not the best way or UI. But this is the only flag that makes sense
regExp = new RegExp(funcname.substring(0, funcname.length - 2), 'i');
}
functions = this.functionSymbols.filter((s) => regExp.test(s.name));
}

let url: string;

if (functions.length === 0) {
vscode.window.showErrorMessage(`No function with name ${funcname} found.`);
vscode.window.showErrorMessage(`No function matching name/regexp '${funcname}' found.`);
}
else if (functions.length === 1) {
if (!functions[0].file || (functions[0].scope === SymbolScope.Global)) {
Expand All @@ -174,6 +182,9 @@ export class CortexDebugExtension {
url = `disassembly:///${functions[0].file}:::${functions[0].name}.cdasm`;
}
}
else if (functions.length > 31) { /* arbitrary limit. 31 is prime! */
vscode.window.showErrorMessage(`Too many(${functions.length}) functions matching '${funcname}' found.`);
}
else {
const selected = await vscode.window.showQuickPick(functions.map((f) => {
return {
Expand Down

0 comments on commit 03bf581

Please sign in to comment.