GDB에서 run 이후에 명령 주소가 바뀌는 것에 대해 질문드립니다.

익명 사용자의 이미지

일단 C로 간단하게 짜고 GDB로 디버깅해 보았습니다.
아래는 gdb를 실행시키고 아직 run 하지 않은 상태에서 disas main을 해본 상태입니다.

(gdb) disas main
Dump of assembler code for function main:
   0x0000000000000710 <+0>:	push   %rbp
   0x0000000000000711 <+1>:	mov    %rsp,%rbp
   0x0000000000000714 <+4>:	sub    $0x10,%rsp
   0x0000000000000718 <+8>:	mov    %fs:0x28,%rax
   0x0000000000000721 <+17>:	mov    %rax,-0x8(%rbp)
   0x0000000000000725 <+21>:	xor    %eax,%eax
   0x0000000000000727 <+23>:	movl   $0x3,-0xc(%rbp)
   0x000000000000072e <+30>:	lea    -0xc(%rbp),%rax
   0x0000000000000732 <+34>:	mov    %rax,%rsi
   0x0000000000000735 <+37>:	lea    0xb8(%rip),%rdi        # 0x7f4
   0x000000000000073c <+44>:	mov    $0x0,%eax
   0x0000000000000741 <+49>:	callq  0x5c8
   0x0000000000000746 <+54>:	mov    $0x0,%eax
   0x000000000000074b <+59>:	mov    -0x8(%rbp),%rdx
   0x000000000000074f <+63>:	xor    %fs:0x28,%rdx
   0x0000000000000758 <+72>:	je     0x75f <main+79>
   0x000000000000075a <+74>:	callq  0x5c0
   0x000000000000075f <+79>:	leaveq 
   0x0000000000000760 <+80>:	retq   
End of assembler dump.
(gdb)

위와같이 명령 주소가 나옵니다.
(gdb) b *0x710
Breakpoint 1 at 0x710
(gdb) run
Starting program: /home/user/tt 
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x710
 
(gdb) disas main
Dump of assembler code for function main:
   0x0000555555554710 <+0>:	push   %rbp
   0x0000555555554711 <+1>:	mov    %rsp,%rbp
   0x0000555555554714 <+4>:	sub    $0x10,%rsp
   0x0000555555554718 <+8>:	mov    %fs:0x28,%rax
   0x0000555555554721 <+17>:	mov    %rax,-0x8(%rbp)
   0x0000555555554725 <+21>:	xor    %eax,%eax
   0x0000555555554727 <+23>:	movl   $0x3,-0xc(%rbp)
   0x000055555555472e <+30>:	lea    -0xc(%rbp),%rax
   0x0000555555554732 <+34>:	mov    %rax,%rsi
   0x0000555555554735 <+37>:	lea    0xb8(%rip),%rdi        # 0x5555555547f4
   0x000055555555473c <+44>:	mov    $0x0,%eax
   0x0000555555554741 <+49>:	callq  0x5555555545c8
   0x0000555555554746 <+54>:	mov    $0x0,%eax
   0x000055555555474b <+59>:	mov    -0x8(%rbp),%rdx
   0x000055555555474f <+63>:	xor    %fs:0x28,%rdx
   0x0000555555554758 <+72>:	je     0x55555555475f <main+79>
   0x000055555555475a <+74>:	callq  0x5555555545c0
   0x000055555555475f <+79>:	leaveq 
   0x0000555555554760 <+80>:	retq   
End of assembler dump.
(gdb)

그래서 한번 0x710 부분에 breakpoint를 걸고 run을 시켰는데... 메모리에 접근할 수 없다고 나와버립니다;;
다시 disas main을 해보니 주소가 저렇게 바뀌어 있더군요.
아무래도 재배치 관련해서 일어나는 문제인 것 같은데 이런 경우에 breakpoint를 주소로 잡을 때 미리 한번 실행시키고 disas를 해서 잡아야하는 건가요?
그리고 저렇게 재배치되지 않게 하려면 컴파일 옵션을 다르게 줘야하는건가요?

OS는 우분투 16.10를 사용하였습니다.

익명 사용자의 이미지

사실 리눅스 gdb에서 실행 파일을 불러 오면 그 실행 파일에 대한 ASLR은 꺼져 있긴 합니다만, 저건 PIE base address 문제라고 알고 있습니다. breakpoint를 걸 때 절댓값이 아닌 main 함수에 대한 상댓값으로 걸면 재배치가 어떻게 되든 상관 없습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.