[Lldb-commits] [lldb] 476f520 - [lldb] Fix SLEB128 decoding
Jan Kratochvil via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 4 10:42:21 PDT 2020
Author: Jan Kratochvil
Date: 2020-06-04T19:41:24+02:00
New Revision: 476f520a0bd29d74f559ea1151ac8d0b428d9150
URL: https://github.com/llvm/llvm-project/commit/476f520a0bd29d74f559ea1151ac8d0b428d9150
DIFF: https://github.com/llvm/llvm-project/commit/476f520a0bd29d74f559ea1151ac8d0b428d9150.diff
LOG: [lldb] Fix SLEB128 decoding
Bug 46181 shows SLEB128 0xED9A924C00011151 decoded as 0xffffffff80011151.
LLDB show a wrong value for function argument
https://bugs.llvm.org/show_bug.cgi?id=46181
Differential Revision: https://reviews.llvm.org/D81119
Added:
lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_const_value.s
Modified:
lldb/source/Utility/DataExtractor.cpp
lldb/unittests/Utility/DataExtractorTest.cpp
Removed:
################################################################################
diff --git a/lldb/source/Utility/DataExtractor.cpp b/lldb/source/Utility/DataExtractor.cpp
index 40819f107052..5f4abb82163e 100644
--- a/lldb/source/Utility/DataExtractor.cpp
+++ b/lldb/source/Utility/DataExtractor.cpp
@@ -931,7 +931,7 @@ int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const {
// Sign bit of byte is 2nd high order bit (0x40)
if (shift < size && (byte & 0x40))
- result |= -(1 << shift);
+ result |= -(static_cast<int64_t>(1) << shift);
*offset_ptr += bytecount;
return result;
diff --git a/lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_const_value.s b/lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_const_value.s
new file mode 100644
index 000000000000..a6d4f199a647
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/DW_TAG_variable-DW_AT_const_value.s
@@ -0,0 +1,85 @@
+# This tests that lldb is able to print DW_TAG_variable using DW_AT_const_value.
+
+# REQUIRES: x86
+
+# RUN: llvm-mc -triple x86_64-unknown-linux-gnu %s -filetype=obj > %t.o
+# RUN: %lldb %t.o -o "p/x magic64" -o exit | FileCheck %s
+
+# CHECK: (const long) $0 = 0xed9a924c00011151
+
+# The DW_TAG_variable using DW_AT_const_value. can be produced from:
+# static const long magic64 = 0xed9a924c00011151;
+# int main(void) { return magic64; }
+
+ .text
+ .globl main # -- Begin function main
+ .type main, at function
+main: # @main
+.Lfunc_end0:
+ .size main, .Lfunc_end0-main
+ # -- End function
+ .section .debug_abbrev,"", at progbits
+ .byte 1 # Abbreviation Code
+ .byte 17 # DW_TAG_compile_unit
+ .byte 1 # DW_CHILDREN_yes
+ .byte 37 # DW_AT_producer
+ .byte 8 # DW_FORM_string
+ .byte 19 # DW_AT_language
+ .byte 5 # DW_FORM_data2
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 2 # Abbreviation Code
+ .byte 52 # DW_TAG_variable
+ .byte 0 # DW_CHILDREN_no
+ .byte 3 # DW_AT_name
+ .byte 8 # DW_FORM_string
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 28 # DW_AT_const_value
+# .byte 15 # DW_FORM_udata
+ .byte 13 # DW_FORM_sdata
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 3 # Abbreviation Code
+ .byte 38 # DW_TAG_const_type
+ .byte 0 # DW_CHILDREN_no
+ .byte 73 # DW_AT_type
+ .byte 19 # DW_FORM_ref4
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 4 # Abbreviation Code
+ .byte 36 # DW_TAG_base_type
+ .byte 0 # DW_CHILDREN_no
+ .byte 3 # DW_AT_name
+ .byte 8 # DW_FORM_string
+ .byte 62 # DW_AT_encoding
+ .byte 11 # DW_FORM_data1
+ .byte 11 # DW_AT_byte_size
+ .byte 11 # DW_FORM_data1
+ .byte 0 # EOM(1)
+ .byte 0 # EOM(2)
+ .byte 0 # EOM(3)
+ .section .debug_info,"", at progbits
+.Lcu_begin0:
+ .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+.Ldebug_info_start0:
+ .short 4 # DWARF version number
+ .long .debug_abbrev # Offset Into Abbrev. Section
+ .byte 8 # Address Size (in bytes)
+ .byte 1 # Abbrev [1] 0xb:0x61 DW_TAG_compile_unit
+ .asciz "clang version 10.0.0" # DW_AT_producer
+ .short 12 # DW_AT_language
+ .byte 2 # Abbrev [2] 0x2a:0x15 DW_TAG_variable
+ .asciz "magic64" # DW_AT_name
+ .long .Lconst # DW_AT_type
+ .sleb128 0xed9a924c00011151 # DW_AT_const_value
+.Lconst:
+ .byte 3 # Abbrev [3] 0x3f:0x5 DW_TAG_const_type
+ .long .Lint64 # DW_AT_type
+.Lint64:
+ .byte 4 # Abbrev [4] 0x44:0x7 DW_TAG_base_type
+ .asciz "long int" # DW_AT_name
+ .byte 5 # DW_AT_encoding
+ .byte 8 # DW_AT_byte_size
+ .byte 0 # End Of Children Mark
+.Ldebug_info_end0:
diff --git a/lldb/unittests/Utility/DataExtractorTest.cpp b/lldb/unittests/Utility/DataExtractorTest.cpp
index f412ab8e79ab..109c15297b16 100644
--- a/lldb/unittests/Utility/DataExtractorTest.cpp
+++ b/lldb/unittests/Utility/DataExtractorTest.cpp
@@ -261,3 +261,41 @@ TEST(DataExtractorTest, GetMaxU64_unchecked) {
EXPECT_EQ(0x0102030405060708U, BE.GetMaxU64_unchecked(&offset, 8));
EXPECT_EQ(8U, offset);
}
+
+TEST(DataExtractorTest, GetSLEB128_bit63) {
+ uint8_t buffer[] = {0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0x7f};
+
+ DataExtractor LE(buffer, sizeof(buffer), lldb::eByteOrderLittle,
+ sizeof(void *));
+ DataExtractor BE(buffer, sizeof(buffer), lldb::eByteOrderBig, sizeof(void *));
+
+ lldb::offset_t offset;
+
+ int64_t expected =
+ 0b1111111100000001111111000000011111110000000111111100000001111111;
+ offset = 0;
+ EXPECT_EQ(expected, LE.GetSLEB128(&offset));
+ EXPECT_EQ(9U, offset);
+ offset = 0;
+ EXPECT_EQ(expected, BE.GetSLEB128(&offset));
+ EXPECT_EQ(9U, offset);
+}
+
+TEST(DataExtractorTest, GetULEB128_bit63) {
+ uint8_t buffer[] = {0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0x7f};
+
+ DataExtractor LE(buffer, sizeof(buffer), lldb::eByteOrderLittle,
+ sizeof(void *));
+ DataExtractor BE(buffer, sizeof(buffer), lldb::eByteOrderBig, sizeof(void *));
+
+ lldb::offset_t offset;
+
+ uint64_t expected =
+ 0b0111111100000001111111000000011111110000000111111100000001111111;
+ offset = 0;
+ EXPECT_EQ(expected, LE.GetULEB128(&offset));
+ EXPECT_EQ(9U, offset);
+ offset = 0;
+ EXPECT_EQ(expected, BE.GetULEB128(&offset));
+ EXPECT_EQ(9U, offset);
+}
More information about the lldb-commits
mailing list