Fix bug in SOS PrintManagedFrameContext (64-bit regs) accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix tizen_6.0 tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.120818 accepted/tizen/6.0/unified/hotfix/20201103.050024 accepted/tizen/unified/20200907.144051 submit/tizen/20200901.065247 submit/tizen_6.0/20201029.205103 submit/tizen_6.0_hotfix/20201102.192503 submit/tizen_6.0_hotfix/20201103.114803 tizen_6.0.m2_release
authorKirill Frolov <k.frolov@samsung.com>
Fri, 28 Aug 2020 10:45:06 +0000 (13:45 +0300)
committerAlexander Soldatov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Thu, 3 Sep 2020 17:12:11 +0000 (20:12 +0300)
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

src/SOS/Strike/strike.cpp

index f43c47cbda52a33551921b65ed046f2a8df0d6ff..8aff39c1bc46794fda226b4478cca03c56fdbb5a 100644 (file)
@@ -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