LoginSignup
17
10

More than 5 years have passed since last update.

書籍「低レベルプログラミング」アセンブリ実行 Docker 環境の構築

Last updated at Posted at 2018-03-13

はじめに

  • 書籍「低レベルプログラミング」では VMWare イメージで実行環境が提供されているが Docker を使いたかったので構築したメモ。
  • 書籍内ではアセンブリの後に C もやるが、まだ最初なのでとりあえずアセンブラが動くところまで。

環境構築

  • Dockerfile の作成
FROM debian:9

RUN apt-get update
RUN apt-get install -y binutils nasm gdb
RUN apt-get install -y vim
  • Docker イメージの作成
docker build -t low-level-programming .

実行

git clone https://github.com/Apress/low-level-programming
  • コードをマウントして Docker イメージの実行
cd /path/to/low-level-programming
docker run -it -v $(pwd)/listings:/listings low-level-programming bash
  • hello.asm のコンパイルと実行
cd /tmp
nasm -felf64 /listings/chap2/hello/hello.asm -o hello.o
ld -o hello hello.o
./hello

デバッガの実行

  • Docker コンテナ内でデバッガを有効にするために実行オプションを追加する
docker run -it --cap-add=SYS_PTRACE --security-opt="seccomp=unconfined" -v $(pwd)/listings:/listings low-level-programming bash
  • gdb コマンドでデバッガを起動する
# コンパイルとデバッガの実行
nasm -felf64 /listings/chap2/hello/hello.asm -o hello.o
ld -o hello hello.o
gdb hello

# アセンブリ向けレイアウトの表示
(gdb) layout asm

# レジスタを表示するレイアウト
(gdb) layout regs

# ブレークポイントを設定する
(gdb) b _start

# 実行
(gdb) run

# 一ステップ実行
(gdb) si

# print $"レジスタ名" でレジスタの値を表示
(gdb) p $cl

# 終了
(gdb) quit
17
10
1

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
17
10