https://www.recurse.com/blog/7-understanding-c-by-learning-assembly [Understanding C by learning assembly]
http://cs.ecs.baylor.edu/~donahoo/tools/valgrind/messages.html [Excerpt from Valgrind documentation]
https://valgrind.org/docs/manual/quick-start.html [The Valgrind Quick Start Guide]
Dump of assembler code for function main:
0x00005555555547f2 <+0>: push %rbp
0x00005555555547f3 <+1>: mov %rsp,%rbp
=> 0x00005555555547f6 <+4>: mov $0x1,%edi
0x00005555555547fb <+9>: callq 0x555555554660 <malloc@plt>
0x0000555555554800 <+14>: mov %rax,0x200821(%rip) # 0x555555755028 <A>
0x0000555555554807 <+21>: mov $0x1,%edi
0x000055555555480c <+26>: callq 0x555555554660 <malloc@plt>
0x0000555555554811 <+31>: mov %rax,0x200800(%rip) # 0x555555755018 <B>
0x0000555555554818 <+38>: mov 0x200809(%rip),%rax # 0x555555755028 <A>
0x000055555555481f <+45>: movb $0x62,(%rax)
0x0000555555554822 <+48>: mov 0x2007ef(%rip),%rax # 0x555555755018 <B>
0x0000555555554829 <+55>: movb $0x61,(%rax)
0x000055555555482c <+58>: mov 0x2007f5(%rip),%rax # 0x555555755028 <A>
0x0000555555554833 <+65>: mov %rax,%rsi
0x0000555555554836 <+68>: lea 0x1c4(%rip),%rdi # 0x555555554a01
0x000055555555483d <+75>: mov $0x0,%eax
0x0000555555554842 <+80>: callq 0x555555554650 <printf@plt>
0x0000555555554847 <+85>: mov 0x2007ca(%rip),%rax # 0x555555755018 <B>
0x000055555555484e <+92>: mov %rax,%rsi
0x0000555555554851 <+95>: lea 0x1bd(%rip),%rdi # 0x555555554a15
0x0000555555554858 <+102>: mov $0x0,%eax
0x000055555555485d <+107>: callq 0x555555554650 <printf@plt>
0x0000555555554862 <+112>: mov 0x2007bf(%rip),%rax # 0x555555755028 <A>
0x0000555555554869 <+119>: movzbl (%rax),%eax
0x000055555555486c <+122>: mov %al,0x2007ae(%rip) # 0x555555755020 <words>
0x0000555555554872 <+128>: movb $0x0,0x2007a8(%rip) # 0x555555755021 <words+1>
0x0000555555554879 <+135>: mov 0x200798(%rip),%rax # 0x555555755018 <B>
0x0000555555554880 <+142>: movzbl (%rax),%eax
0x0000555555554883 <+145>: mov %al,0x200799(%rip) # 0x555555755022
0x0000555555554889 <+151>: movb $0x0,0x200793(%rip) # 0x555555755023
0x0000555555554890 <+158>: lea 0x192(%rip),%rdi # 0x555555554a29
0x0000555555554897 <+165>: callq 0x555555554630 <puts@plt>
0x000055555555489c <+170>: lea 0x20077d(%rip),%rsi # 0x555555755020 <words>
0x00005555555548a3 <+177>: lea 0x19d(%rip),%rdi # 0x555555554a47
0x00005555555548aa <+184>: mov $0x0,%eax
0x00005555555548af <+189>: callq 0x555555554650 <printf@plt>
0x00005555555548b4 <+194>: lea 0x200767(%rip),%rsi # 0x555555755022
0x00005555555548bb <+201>: lea 0x19e(%rip),%rdi # 0x555555554a60
0x00005555555548c2 <+208>: mov $0x0,%eax
0x00005555555548c7 <+213>: callq 0x555555554650 <printf@plt>
0x00005555555548cc <+218>: mov 0x200745(%rip),%rax # 0x555555755018 <B>
0x00005555555548d3 <+225>: movzbl (%rax),%eax
0x00005555555548d6 <+228>: movsbl %al,%edx
0x00005555555548d9 <+231>: mov 0x200748(%rip),%rax # 0x555555755028 <A>
0x00005555555548e0 <+238>: movzbl (%rax),%eax
0x00005555555548e3 <+241>: movsbl %al,%eax
0x00005555555548e6 <+244>: mov %edx,%esi
0x00005555555548e8 <+246>: mov %eax,%edi
0x00005555555548ea <+248>: callq 0x55555555478a <mergeChars>
0x00005555555548ef <+253>: mov 0x200732(%rip),%rax # 0x555555755028 <A>
0x00005555555548f6 <+260>: mov %rax,%rdi
0x00005555555548f9 <+263>: callq 0x555555554620 <free@plt>
0x00005555555548fe <+268>: mov 0x200713(%rip),%rax # 0x555555755018 <B>
0x0000555555554905 <+275>: mov %rax,%rdi
0x0000555555554908 <+278>: callq 0x555555554620 <free@plt>
0x000055555555490d <+283>: lea 0x165(%rip),%rdi # 0x555555554a79
0x0000555555554914 <+290>: callq 0x555555554630 <puts@plt>
0x0000555555554919 <+295>: lea 0x200700(%rip),%rsi # 0x555555755020 <words>
0x0000555555554920 <+302>: lea 0x120(%rip),%rdi # 0x555555554a47
0x0000555555554927 <+309>: mov $0x0,%eax
0x000055555555492c <+314>: callq 0x555555554650 <printf@plt>
0x0000555555554931 <+319>: lea 0x2006ea(%rip),%rsi # 0x555555755022
0x0000555555554938 <+326>: lea 0x121(%rip),%rdi # 0x555555554a60
0x000055555555493f <+333>: mov $0x0,%eax
0x0000555555554944 <+338>: callq 0x555555554650 <printf@plt>
0x0000555555554949 <+343>: lea 0x143(%rip),%rdi # 0x555555554a93
0x0000555555554950 <+350>: callq 0x555555554630 <puts@plt>
0x0000555555554955 <+355>: mov $0x0,%eax
0x000055555555495a <+360>: pop %rbp
0x000055555555495b <+361>: retq
End of assembler dump.
--------------------------------------------------------------------------------------------------------------------------
==6155== by 0x108846: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155== Address 0x522d041 is 0 bytes after a block of size 1 alloc'd
==6155== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x1087FF: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155==
--6155-- REDIR: 0x4fcad20 (libc.so.6:__mempcpy_avx_unaligned_erms) redirected to 0x4c37130 (mempcpy)
A is currently: b
==6155== Invalid read of size 1
==6155== at 0x4C32D04: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x4E99562: vfprintf (vfprintf.c:1643)
==6155== by 0x4EA0FA5: printf (printf.c:33)
==6155== by 0x108861: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155== Address 0x522d091 is 0 bytes after a block of size 1 alloc'd
==6155== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x108810: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155==
B is currently: a
before the memory is freed:
here is the words[0] b
here is the words[1] a
Here is something with A 98
*** stack smashing detected ***: <unknown> terminated
==6155==
==6155== Process terminating with default action of signal 6 (SIGABRT)
==6155== at 0x4E7AF47: raise (raise.c:51)
==6155== by 0x4E7C8B0: abort (abort.c:79)
==6155== by 0x4EC5906: __libc_message (libc_fatal.c:181)
==6155== by 0x4F70E80: __fortify_fail_abort (fortify_fail.c:33)
==6155== by 0x4F70E41: __stack_chk_fail (stack_chk_fail.c:29)
==6155== by 0x1087EF: mergeChars (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155== by 0x1088EE: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
--6155-- REDIR: 0x4ed39c0 (libc.so.6:free) redirected to 0x4c30cd0 (free)
==6155==
==6155== HEAP SUMMARY:
==6155== in use at exit: 2 bytes in 2 blocks
==6155== total heap usage: 3 allocs, 1 frees, 1,026 bytes allocated
==6155==
==6155== Searching for pointers to 2 not-freed blocks
==6155== Checked 74,008 bytes
==6155==
==6155== 1 bytes in 1 blocks are still reachable in loss record 1 of 2
==6155== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x1087FF: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155==
==6155== 1 bytes in 1 blocks are still reachable in loss record 2 of 2
==6155== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x108810: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155==
==6155== LEAK SUMMARY:
==6155== definitely lost: 0 bytes in 0 blocks
==6155== indirectly lost: 0 bytes in 0 blocks
==6155== possibly lost: 0 bytes in 0 blocks
==6155== still reachable: 2 bytes in 2 blocks
==6155== suppressed: 0 bytes in 0 blocks
==6155==
==6155== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
==6155==
==6155== 1 errors in context 1 of 2:
==6155== Invalid read of size 1
==6155== at 0x4C32D04: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x4E99562: vfprintf (vfprintf.c:1643)
==6155== by 0x4EA0FA5: printf (printf.c:33)
==6155== by 0x108861: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155== Address 0x522d091 is 0 bytes after a block of size 1 alloc'd
==6155== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x108810: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155==
==6155==
==6155== 1 errors in context 2 of 2:
==6155== Invalid read of size 1
==6155== at 0x4C32D04: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x4E99562: vfprintf (vfprintf.c:1643)
==6155== by 0x4EA0FA5: printf (printf.c:33)
==6155== by 0x108846: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155== Address 0x522d041 is 0 bytes after a block of size 1 alloc'd
==6155== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6155== by 0x1087FF: main (in /home/ubuntu/Downloads/changearray/ifstructures/loopbyFour/mergeCharsFuncation/tryThree)
==6155==
==6155== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Aborted (core dumped)
No comments:
Post a Comment