From 7f2cf709c55467f4b63b334ac2e05214ce8f8853 Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Mon, 25 Nov 2024 11:39:47 +0100 Subject: [PATCH] Add @d @f commands for advanced debugging with addr --- hld/Value.hx | 21 +++++++++++++++++++++ src/HLAdapter.hx | 27 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/hld/Value.hx b/hld/Value.hx index 205dc51..5954053 100644 --- a/hld/Value.hx +++ b/hld/Value.hx @@ -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 ) { diff --git a/src/HLAdapter.hx b/src/HLAdapter.hx index e749a77..9742783 100644 --- a/src/HLAdapter.hx +++ b/src/HLAdapter.hx @@ -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);