Skip to content

Commit

Permalink
Add @d @f commands for advanced debugging with addr
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao committed Nov 25, 2024
1 parent d9b47ce commit 7f2cf70
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions hld/Value.hx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ enum Hint {
return prefix + s;
}

public static function parseInt64( str : String ) : haxe.Int64 {
var value = haxe.Int64.make(0, 0);
var base = 16;
var shift = 4;
var i = 0;
if( StringTools.startsWith(str,"0x") ) {
i += 2;
}
while( i < str.length ) {
var c = str.charCodeAt(i);
var cval = if( c >= '0'.code && c <= '9'.code ) c - '0'.code
else if( c >= 'A'.code && c <= 'F'.code ) c - 'A'.code + 10
else if( c >= 'a'.code && c <= 'f'.code ) c - 'a'.code + 10
else
break;
value = (value << shift) + cval;
i++;
}
return value;
}

public static function intEnumFlags( value : Int, eproto : format.hl.Data.EnumPrototype ) : String {
var f = "";
for( i in 0...eproto.constructs.length ) {
Expand Down
27 changes: 27 additions & 0 deletions src/HLAdapter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,33 @@ class HLAdapter extends DebugSession {
args.expression = args.expression.substr(1);
if( KEYWORDS.exists(args.expression) ) {
// Do nothing
} else if( args.expression.charCodeAt(0) == '@'.code ) {
// Advanced commands based on address
switch( args.expression.charCodeAt(1) ) {
case 'd'.code:
// @d + ptr: try to evaluate pointer as Dynamic value
var p = new hld.Pointer(hld.Value.parseInt64(args.expression.substr(2)));
var value = @:privateAccess dbg.eval.convertVal(p, HDyn);
value.hint = HPointer;
var v = makeVar("", value);
response.body = {
result : v.value,
type : v.type,
variablesReference : v.variablesReference,
namedVariables : v.namedVariables,
indexedVariables : v.indexedVariables,
};
case 'f'.code:
// @f + ptr: try to evaluate pointer as FunRepr
var p = new hld.Pointer(hld.Value.parseInt64(args.expression.substr(2)));
@:privateAccess var index = dbg.jit.functionFromAddr(p);
response.body = {
result : dbg.eval.funStr(index == null ? FUnknown(p) : FIndex(index, p), true),
variablesReference : 0,
};
default:
debug("Unsupported command");
}
} else {
var value = dbg.getValue(args.expression);
var v = makeVar("", value);
Expand Down

0 comments on commit 7f2cf70

Please sign in to comment.