From 9bf85e1e67c657b5bf166b4c67cb216bc0d512b4 Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 6 Dec 2019 12:23:06 +0000 Subject: [PATCH] ide: PDB debugger improvements git-svn-id: svn://ultimatepp.org/upp/trunk@13740 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Debuggers/Pdb.h | 5 ++++- uppsrc/ide/Debuggers/Pretty.cpp | 2 +- uppsrc/ide/Debuggers/Sym.cpp | 10 +++++++--- uppsrc/ide/Debuggers/Tree.cpp | 2 +- uppsrc/ide/Debuggers/Visualise.cpp | 24 ++++++++++++++++-------- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/uppsrc/ide/Debuggers/Pdb.h b/uppsrc/ide/Debuggers/Pdb.h index f3f2d2289..e12eee44c 100644 --- a/uppsrc/ide/Debuggers/Pdb.h +++ b/uppsrc/ide/Debuggers/Pdb.h @@ -86,7 +86,8 @@ struct Pdb : Debugger, ParentCtrl { struct TypeInfo : Moveable { int type = UNKNOWN; - int ref = 0; // this is pointer (or reference) + int ref = 0; // this is pointer or reference + bool reference = false; // this is reference }; struct Val : Moveable { @@ -343,6 +344,8 @@ struct Pdb : Debugger, ParentCtrl { String TypeInfoAsString(TypeInfo tf); TypeInfo GetTypeInfo(adr_t modbase, const String& name); TypeInfo GetTypeInfo(const String& name) { return GetTypeInfo(current_modbase, name); } // only in Pretty... + + static String FormatString(const String& x) { return AsCString(x, INT_MAX, NULL, CheckUtf8(x) ? 0 : ASCSTRING_OCTALHI); } // exp Val MakeVal(const String& type, adr_t address); diff --git a/uppsrc/ide/Debuggers/Pretty.cpp b/uppsrc/ide/Debuggers/Pretty.cpp index 467ede4e8..38b8caa0e 100644 --- a/uppsrc/ide/Debuggers/Pretty.cpp +++ b/uppsrc/ide/Debuggers/Pretty.cpp @@ -388,7 +388,7 @@ bool Pdb::VisualisePretty(Visual& result, Pdb::Val val, dword flags) ws.Cat(PeekWord(a)); } ResultCount(p.data_count); - result.Cat(AsCString(sz == 1 ? s : ws.ToString()), SRed); + result.Cat(FormatString(sz == 1 ? s : ws.ToString()), SRed); if(p.data_count > p.data_ptr.GetCount()) result.Cat("..", SGray); } diff --git a/uppsrc/ide/Debuggers/Sym.cpp b/uppsrc/ide/Debuggers/Sym.cpp index fcecbdfd0..2fd551f90 100644 --- a/uppsrc/ide/Debuggers/Sym.cpp +++ b/uppsrc/ide/Debuggers/Sym.cpp @@ -128,6 +128,12 @@ Pdb::FnInfo Pdb::GetFnInfo(adr_t address) void Pdb::TypeVal(Pdb::Val& v, int typeId, adr_t modbase) { adr_t tag; + + BOOL reference; + dword dw = 0; + SymGetTypeInfo(hProcess, modbase, typeId, TI_GET_IS_REFERENCE, &reference); + v.reference = reference; + for(;;) { tag = GetSymInfo(modbase, typeId, TI_GET_SYMTAG); if(tag == SymTagPointerType) @@ -206,17 +212,16 @@ BOOL CALLBACK Pdb::EnumLocals(PSYMBOL_INFO pSym, ULONG SymbolSize, PVOID UserCon else if(pSym->Flags & IMAGEHLP_SYMBOL_INFO_FRAMERELATIVE) v.address += c.frame; + LLOG("LOCAL " << pSym->Name << ": " << Format64Hex(v.address)); c.pdb->TypeVal(v, pSym->TypeIndex, (adr_t)pSym->ModBase); v.reported_size = pSym->Size; v.context = c.context; - DLOG("LOCAL " << pSym->Name << ": " << Format64Hex(v.address)); return TRUE; } void Pdb::GetLocals(Frame& frame, Context& context, VectorMap& param, VectorMap& local) { - DLOG("============ GetLocals"); static IMAGEHLP_STACK_FRAME f; f.InstructionOffset = frame.pc; SymSetContext(hProcess, &f, 0); @@ -227,7 +232,6 @@ void Pdb::GetLocals(Frame& frame, Context& context, VectorMap& SymEnumSymbols(hProcess, 0, 0, &EnumLocals, &c); param = pick(c.param); local = pick(c.local); - DLOG("..."); } BOOL CALLBACK Pdb::EnumGlobals(PSYMBOL_INFO pSym, ULONG SymbolSize, PVOID UserContext) diff --git a/uppsrc/ide/Debuggers/Tree.cpp b/uppsrc/ide/Debuggers/Tree.cpp index 6c2fc2ec7..ab9c5a239 100644 --- a/uppsrc/ide/Debuggers/Tree.cpp +++ b/uppsrc/ide/Debuggers/Tree.cpp @@ -215,7 +215,7 @@ void Pdb::ExpandTreeType(int parent, CParser& p) id << AsString(p.ReadInt()); else if(p.IsString()) - id << '\"' << AsCString(p.ReadString()) << '\"'; + id << '\"' << FormatString(p.ReadString()) << '\"'; else if(p.IsId()) id << p.ReadId(); diff --git a/uppsrc/ide/Debuggers/Visualise.cpp b/uppsrc/ide/Debuggers/Visualise.cpp index e1389e7d2..8ac4c6ec5 100644 --- a/uppsrc/ide/Debuggers/Visualise.cpp +++ b/uppsrc/ide/Debuggers/Visualise.cpp @@ -106,13 +106,16 @@ void Pdb::Visualise(Visual& result, Pdb::Val val, dword flags) if(val.ref > 0 || val.type < 0) // if pointer or primitive type, fetch it from the memory val = GetRVal(val); if(val.ref > 0) { - result.Cat(Hex(val.address), SLtMagenta); + if(!val.reference) + result.Cat(Hex(val.address), SLtMagenta); while(val.ref > 1) { val = GetRVal(DeRef(val)); - result.Cat("->"); - result.Cat(Hex(val.address), SLtMagenta); + if(!val.reference) { + result.Cat("->"); + result.Cat(Hex(val.address), SLtMagenta); + } } - if(val.type == UINT1 || val.type == SINT1) { // show string at [unsigned] char * + if((val.type == UINT1 || val.type == SINT1) && !val.reference) { // show string at [unsigned] char * if(Byte(val.address) < 0) result.Cat("??", SColorDisabled); else { @@ -124,16 +127,21 @@ void Pdb::Visualise(Visual& result, Pdb::Val val, dword flags) dt = ".."; } result.Cat(" "); - result.Cat(AsCString(x), SRed); + result.Cat(FormatString(x), SRed); result.Cat(dt, SGray); } return; } if(!(flags & MEMBER) && val.type != UNKNOWN && val.address) { - result.Cat("->", SColorMark); + if(!val.reference) + result.Cat("->", SColorMark); int sz = SizeOfType(val.type); int n = 40; String dt = ".."; + if(val.reference) { + n = 1; + dt.Clear(); + } if(val.reported_size > sz && sz > 0) { n = val.reported_size / sz; if(n <= 40) @@ -143,7 +151,7 @@ void Pdb::Visualise(Visual& result, Pdb::Val val, dword flags) for(int i = 0; i < n; i++) { if(i) result.Cat(", ", SGray); - Visualise(result, DeRef(val), flags | MEMBER); + Visualise(result, DeRef(val), flags | (val.reference ? 0 : MEMBER)); val.address += sz; if(Byte(val.address) < 0) { dt.Clear(); @@ -326,7 +334,7 @@ Pdb::Visual Pdb::Visualise(const String& exp, dword flags) Size Pdb::VisualPart::GetSize() const { - return GetTextSize(*text < 32 ? "MM" : ~text, StdFont()); + return GetTextSize(*text && *text < 32 ? "MM" : ~text, StdFont()); } Size Pdb::VisualDisplay::GetStdSize(const Value& q) const