{"id":5386,"date":"2014-03-30T21:21:27","date_gmt":"2014-03-30T21:21:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-read-memory-address-in-gdb-for-i7-processor-code-disassembly-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:21:27","modified_gmt":"2014-03-30T21:21:27","slug":"how-to-read-memory-address-in-gdb-for-i7-processor-code-disassembly-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-read-memory-address-in-gdb-for-i7-processor-code-disassembly-collection-of-common-programming-errors\/","title":{"rendered":"How to read memory address in gdb for i7 processor code disassembly?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to read the location of a variable in memory at runtime, using gdb within Eclipse, but can&#8217;t really see which one is the correct address. Here is the output of gdb when I disassembly my program:<\/p>\n<pre><code>                  main():\n0000000000400634:   push %rbp\n0000000000400635:   mov %rsp,%rbp\n 5                  int i = 7;\n0000000000400638:   movl $0x7,-0x4(%rbp)\n 6                  int j = 8;\n000000000040063f:   movl $0x8,-0x8(%rbp)\n 8                  return 0;\n0000000000400646:   mov $0x0,%eax\n 9                }\n<\/code><\/pre>\n<p>and what I want is the location of the variable i at runtime. I&#8217;m guessing it&#8217;s -0x4(%rbp), but then how can I figure out what address that is?<\/p>\n<p>Should I take the current value of rbp and subtract 4 from it? In this case, the value inside rbp is 0x7fffffffe250. Thus, would the location of i in memory at runtime be 0x7fffffffe250 &#8211; 0x4? Or is it just 0x7fffffffe250?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to read the location of a variable in memory at runtime, using gdb within Eclipse, but can&#8217;t really see which one is the correct address. Here is the output of gdb when I disassembly my program: main(): 0000000000400634: push %rbp 0000000000400635: mov %rsp,%rbp 5 int i = 7; 0000000000400638: movl $0x7,-0x4(%rbp) 6 int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5386","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5386"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5386\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}