[Lldb-commits] [lldb] r184877 - Fix undefined behaviour in data formatter test -- ensure char* null-terminated
Ed Maste
emaste at freebsd.org
Wed Jun 26 10:53:14 PDT 2013
On 26 June 2013 04:23, Tim Northover <tnorthover at apple.com> wrote:
> On Tuesday 25 June 2013 20:53:40 Ed Maste wrote:
>> For example, try the following:
>
> Yep, I did some tests along those lines. The only problem is likely to come if
> the pointer is near the last byte of the last page accessible by the program.
> I couldn't provoke a disturbing failure myself, but I saw enough to convince
> myself it's not catastrophic.
Indeed, and I do see some surprising behaviour with that case. New test code:
#include <string.h>
#include <sys/mman.h>
#define MMAP_SIZE 4096
int main(int argc, char **argv)
{
char *buf, *c;
buf = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
memset (buf, 0xa5, MMAP_SIZE);
c = buf + MMAP_SIZE - 4;
*c = 'X';
return 0; // Breakpoint here
}
I can run "frame variable c" twice in a row, with different results:
feynman% /tank/emaste/src/llvm/build/bin/lldb lldb_stack
Current executable set to 'lldb_stack' (x86_64).
(lldb) b lldb_stack.c:17
Breakpoint 1: where = lldb_stack`main + 96 at lldb_stack.c:17, address
= 0x0000000000400680
(lldb) run
Process 25747 launched: '/tank/emaste/src/snippets/lldb_stack' (x86_64)
Process 25747 stopped
* thread #1: tid = 0x6493, 0x0000000000400680 lldb_stack`main(argc=1,
argv=0x00007fffffffd590) + 96 at lldb_stack.c:17, stop reason =
breakpoint 1.1
frame #0: 0x0000000000400680 lldb_stack`main(argc=1,
argv=0x00007fffffffd590) + 96 at lldb_stack.c:17
14 c = buf + MMAP_SIZE - 4;
15 *c = 'X';
16
-> 17 return 0; // Breakpoint here
18 }
(lldb) frame variable c
(char *) c = 0x0000000800639ffc
(lldb) frame variable c
(char *) c = 0x0000000800639ffc "X\xa5\xa5\xa5"
More information about the lldb-commits
mailing list