Printing “array” from .bss in gdb

后端 未结 3 589
眼角桃花
眼角桃花 2021-01-19 10:08

my nasm x86 assembly code contains the following:

; The code should mimic the following C-code:
; int a[10];
; for (int i = 0; i < 10; i++){
;    a[i] = i         


        
3条回答
  •  情歌与酒
    2021-01-19 10:54

    ; The code should mimic the following C-code:

    In addition to wrong boundary noted by Jester, you also have the wrong initialization: your code is equivalent to:

     for (int i = 0; i < 10; i++) {
       a[i] = i + 1;  // different from stated goal of "a[i] = i;"
     }
    

    However, how do i print array?

    This is no different from printing array in C, when the source is compiled without debug info:

    (gdb) p array
    $1 = 0
    
    (gdb) p {int[10]}&array
    $2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
    

    print array + X unfortunately is an arithmetical operation

    You can then use:

    (gdb) p $2[4]
    $3 = 4
    

提交回复
热议问题