From: Kirill Frolov Date: Fri, 28 Aug 2020 10:45:06 +0000 (+0300) Subject: Fix bug in SOS PrintManagedFrameContext (64-bit regs) X-Git-Tag: submit/tizen/20200901.065247^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_6.0_hotfix;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Fix bug in SOS PrintManagedFrameContext (64-bit regs) The bug caused by the following: At first -- Windows and Linux use different data models for 64-bit computing: LLP64 and LP64. sizeof(long) have different values in both models, and printf format specifiers required to print long values might be different. For Linux PRIx (in inttypes.h) defined as "%lx", but it isn't suitable for Windows. At same time PRIx is defined as "%llx" and works for Linux too (because sizeof(long) == sizeof(long long) on 64-bit Linux). Second -- SOS code doesn't use standard functions from C library, instead it uses own implementation from statically linked PAL library. This library assumes LLP64 data model (where sizeof(long) == sizeof(int)), which is differs from LP64 model used in linux compiler's defines, standard C-library include files, etc... Due this incompatibility data values might be printed truncated on Linux when using PRI... macro from stdint.h To avoid truncation of printed values following is needed: 1) avoid using definitions from C-library (PRI... macro from inttypes.h); 2) don't print "long" data type as is, convert it to long long and print with use "%ll..." format specifier. Also see comments at line 180 in pal_mstypes.h --- diff --git a/src/SOS/Strike/strike.cpp b/src/SOS/Strike/strike.cpp index f43c47cbd..8aff39c1b 100644 --- a/src/SOS/Strike/strike.cpp +++ b/src/SOS/Strike/strike.cpp @@ -13768,8 +13768,8 @@ public: if (IsDbgTargetAmd64()) { foundPlatform = true; - String outputFormat3 = " %3s=%016" PRIx64" %3s=%016" PRIx64" %3s=%016" PRIx64"\n"; - String outputFormat2 = " %3s=%016" PRIx64" %3s=%016" PRIx64"\n"; + String outputFormat3 = " %3s=%016llx %3s=%016llx %3s=%016llx\n"; + String outputFormat2 = " %3s=%016llx %3s=%016llx\n"; ExtOut(outputFormat3, "rsp", context.Amd64Context.Rsp, "rbp", context.Amd64Context.Rbp, "rip", context.Amd64Context.Rip); ExtOut(outputFormat3, "rax", context.Amd64Context.Rax, "rbx", context.Amd64Context.Rbx, "rcx", context.Amd64Context.Rcx); ExtOut(outputFormat3, "rdx", context.Amd64Context.Rdx, "rsi", context.Amd64Context.Rsi, "rdi", context.Amd64Context.Rdi); @@ -13815,11 +13815,11 @@ public: for (int i = 0; i < 29; ++i) { if (i <10) ExtOut(" "); - ExtOut(" x%d=%016" PRIx64, i, X[i]); + ExtOut(" x%d=%016llx", i, X[i]); if ((i % 3) == 2) ExtOut("\n "); } - ExtOut(" fp=%016" PRIx64"\n", context.Arm64Context.Fp); - ExtOut(" lr=%016" PRIx64" sp=%016" PRIx64" pc=%016" PRIx64"\n", context.Arm64Context.Lr, context.Arm64Context.Sp, context.Arm64Context.Pc); + ExtOut(" fp=%016llx\n", context.Arm64Context.Fp); + ExtOut(" lr=%016llx sp=%016llx pc=%016llx\n", context.Arm64Context.Lr, context.Arm64Context.Sp, context.Arm64Context.Pc); ExtOut(" cpsr=%08x fpcr=%08x fpsr=%08x\n", context.Arm64Context.Cpsr, context.Arm64Context.Fpcr, context.Arm64Context.Fpsr); } #endif