Jim unintentionally had the gdb-format specifiers falling through

after r276132 so that 'x/4b' would print out a series of 4 8-byte
quantities.  Fix that, add a test case.

<rdar://problem/29930833> 

llvm-svn: 293002
This commit is contained in:
Jason Molenda 2017-01-25 01:41:48 +00:00
parent 4dbf368e14
commit a1609ff658
3 changed files with 40 additions and 17 deletions

View File

@ -118,3 +118,20 @@ class MemoryReadTestCase(TestBase):
'16',
'18',
'20'])
# the gdb format specifier and the size in characters for
# the returned values including the 0x prefix.
variations = [['b', 4], ['h', 6], ['w', 10], ['g', 18]]
for v in variations:
formatter = v[0]
expected_object_length = v[1]
self.runCmd(
"memory read --gdb-format 4%s &my_uint64s" % formatter)
lines = self.res.GetOutput().splitlines()
objects_read = []
for l in lines:
objects_read.extend(l.split(':')[1].split())
# Check that we got back 4 0x0000 etc bytes
for o in objects_read:
self.assertTrue (len(o) == expected_object_length)
self.assertTrue(len(objects_read) == 4)

View File

@ -7,12 +7,14 @@
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include <stdint.h>
int main (int argc, char const *argv[])
{
char my_string[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 0};
double my_double = 1234.5678;
int my_ints[] = {2,4,6,8,10,12,14,16,18,20,22};
uint64_t my_uint64s[] = {0, 1, 2, 3, 4, 5, 6, 7};
printf("my_string=%s\n", my_string); // Set break point at this line.
printf("my_double=%g\n", my_double);
return 0;

View File

@ -235,32 +235,36 @@ bool OptionGroupFormat::ParserGDBFormatLetter(
m_prev_gdb_format = format_letter;
return true;
// Size isn't used for printing instructions, so if a size is specified, and
// the previous format was
// 'i', then we should reset it to the default ('x'). Otherwise we'll
// continue to print as instructions,
// which isn't expected.
case 'b':
byte_size = 1;
LLVM_FALLTHROUGH;
case 'h':
byte_size = 2;
LLVM_FALLTHROUGH;
case 'w':
byte_size = 4;
LLVM_FALLTHROUGH;
case 'g':
byte_size = 8;
m_prev_gdb_size = format_letter;
if (m_prev_gdb_format == 'i')
m_prev_gdb_format = 'x';
return true;
{
// Size isn't used for printing instructions, so if a size is specified, and
// the previous format was
// 'i', then we should reset it to the default ('x'). Otherwise we'll
// continue to print as instructions,
// which isn't expected.
if (format_letter == 'b')
byte_size = 1;
else if (format_letter == 'h')
byte_size = 2;
else if (format_letter == 'w')
byte_size = 4;
else if (format_letter == 'g')
byte_size = 8;
m_prev_gdb_size = format_letter;
if (m_prev_gdb_format == 'i')
m_prev_gdb_format = 'x';
return true;
}
break;
default:
break;
}
return false;
}