<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ものぐさ備忘録 &#187; kprobes</title>
	<atom:link href="http://www.ginriki.net/wd/category/kprobes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ginriki.net/wd</link>
	<description>ソフトウェア関係の話を中心とした備忘録的日記</description>
	<lastBuildDate>Sun, 16 Jan 2011 20:07:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>kprobes &#8211; カーネルへ動的にプローブ挿入</title>
		<link>http://www.ginriki.net/wd/2009/07/13/60/</link>
		<comments>http://www.ginriki.net/wd/2009/07/13/60/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 22:00:42 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[debugger]]></category>
		<category><![CDATA[kprobes]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.ginriki.net/wd/?p=60</guid>
		<description><![CDATA[Debug Hacksを読んでたら、kprobesっていうデバッグツールの話があった。
自分でモジュール作ってinsmodするだけで、カーネル再コンパイルなしで、ある実行地点でのカーネル内変数を調べるツールだそうで。
プ [...]]]></description>
			<content:encoded><![CDATA[<p>Debug Hacksを読んでたら、kprobesっていうデバッグツールの話があった。<br />
自分でモジュール作ってinsmodするだけで、カーネル再コンパイルなしで、ある実行地点でのカーネル内変数を調べるツールだそうで。</p>
<p>プロセスのユーザ空間（＝デバッギのユーザ空間）に対してデバッガプロセスがプローブする場合は<sup>1</sup></p>
<ol>
<li>デバッガプロセスがptrace辺りを使ってデバッギのメモリ空間上の指定アドレス上にあるアセンブリ命令をint 3に書き変えて<sup>2</sup></li>
<li>デバッギプロセス実行中にそのint 3命令実行して発生したSIGTRAPをデバッガプロセスがフック(=これも事前にptraceで設定する）して</li>
<li>デバッガプロセスがptraceでデバッギプロセスのメモリ空間から値をread</li>
</ol>
<p>っていう流れが普通だと思う。<a href="http://www.google.co.jp/codesearch/p?hl=ja&#038;sa=N&#038;cd=5&#038;ct=rc#6MUOKTZ2awo/linux-2.6.19.3/arch/x86_64/kernel/kprobes.c&#038;q=kprobes.c&#038;l=468">kprobes.c</a>のコメントを見てみると、kprobesの場合もカーネルの指定命令アドレスにint 3を入れてるらしい。</p>
<pre>
/*
 * Called after single-stepping.  p->addr is the address of the
 * instruction whose first byte has been replaced by the "int 3"
 * instruction.  To avoid the SMP problems that can occur when we
 * temporarily put back the original opcode to single-step, we
 * single-stepped a copy of the instruction.  The address of this
 * copy is p->ainsn.insn. ...
 * ...
 */
</pre>
<p>ただ、SMPの関係で色々対策が必要なんだね<sup>3</sup>。int 3を実行した後、例外ベクタにジャンプしてからどういう手順で処理してるかについてイメージがわかないから、今度ソース読んでみようかな。</p>
<p>あと、kprobesだと見たい変数（とくにローカル変数などCPUアーキテクチャとデバッグ情報からアドレスを割り出す必要のあるもの）のアドレスを探すのが大変だけど、<br />
kprobes+GDBでそこを解決しようとしてるのが<a href=http://www.red-bean.com/trac/tracepoints/">tracepoints</a>ってやつらしい。ふむふむ。</p>
<ol class="footnotes"><li id="footnote_0_60" class="footnote">以前、<a href="http://www.ginriki.net/wd/2007/05/28/14/">デバッガについて書いた記事</a>もどうぞ。</li><li id="footnote_1_60" class="footnote">int 3はIA-32とかIntel architectureの場合の話です</li><li id="footnote_2_60" class="footnote">デバッギプロセスにプローブする場合に必要なマルチスレッド対策とどの程度一緒なのかは、まだよくわからない。</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2009/07/13/60/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

