0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ARM32 PCレジスタの値をGDBで確認してみる

Last updated at Posted at 2025-10-15

目的

ARM32ビットCPUのPCレジスタには次に実行する命令のアドレスが入っています。
今回は実際に実行して本当に入っているのかを検証します。

コンパイル及び逆アセンブル

as -o test.o test.s
ld -o test test.o
objdump -d test > test.asm
test.s
.global _start
_start:
    MOV R0, #0
    B .

命令毎のアドレスを確認するために、逆アセンブルする。

test.asm
test:     file format elf32-littlearm


Disassembly of section .text:

00010054 <_start>:
   10054:       e3a00000        mov     r0, #0
   10058:       eafffffe        b       10058 <_start+0x4>

GDBでレジスタの中身を確認する

以下の様にGDBで起動し、MOV R0, #0実行直前で動作を止め、
PCレジスタに10054が入っているかを確認する。

操作手順は以下の通り。

gdb test
(gdb) break _start
(gdb) run
(gdb) info registers

実際の操作は以下の通り。
PCレジスタには0x10054が入っている。

testuser@CasaOS:~/atest$ gdb test
GNU gdb (Debian 13.1-3) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test...
(No debugging symbols found in test)
(gdb) break _start
Breakpoint 1 at 0x10054
(gdb) run
Starting program: /home/testuser/atest/test

Breakpoint 1, 0x00010054 in _start ()
(gdb) info registers
r0             0x0                 0
r1             0x0                 0
r2             0x0                 0
r3             0x0                 0
r4             0x0                 0
r5             0x0                 0
r6             0x0                 0
r7             0x0                 0
r8             0x0                 0
r9             0x0                 0
r10            0x0                 0
r11            0x0                 0
r12            0x0                 0
sp             0xbefff560          0xbefff560
lr             0x0                 0
pc             0x10054             0x10054 <_start>
cpsr           0x10                16
fpscr          0x0                 0
tpidruro       <unavailable>
(gdb)

動作環境(Linux / ARM 版)

  • OS: Armbian 23.08.0-trunk (Debian 12 Bookworm)
  • Kernel: Linux 6.1.38-meson (armv7l)
  • CPU: ARM Cortex-A5, 4 cores, Little Endian
  • Architecture: armv7l
  • 備考: Windows10からSSH接続して使用
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?