libunwind-dynamic.man 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. '\" t
  2. .\" Manual page created with latex2man on Thu Aug 16 09:44:44 MDT 2007
  3. .\" NOTE: This file is generated, DO NOT EDIT.
  4. .de Vb
  5. .ft CW
  6. .nf
  7. ..
  8. .de Ve
  9. .ft R
  10. .fi
  11. ..
  12. .TH "LIBUNWIND\-DYNAMIC" "3" "16 August 2007" "Programming Library " "Programming Library "
  13. .SH NAME
  14. libunwind\-dynamic
  15. \-\- libunwind\-support for runtime\-generated code
  16. .PP
  17. .SH INTRODUCTION
  18. .PP
  19. For libunwind
  20. to do its job, it needs to be able to reconstruct
  21. the \fIframe state\fP
  22. of each frame in a call\-chain. The frame state
  23. describes the subset of the machine\-state that consists of the
  24. \fIframe registers\fP
  25. (typically the instruction\-pointer and the
  26. stack\-pointer) and all callee\-saved registers (preserved registers).
  27. The frame state describes each register either by providing its
  28. current value (for frame registers) or by providing the location at
  29. which the current value is stored (callee\-saved registers).
  30. .PP
  31. For statically generated code, the compiler normally takes care of
  32. emitting \fIunwind\-info\fP
  33. which provides the minimum amount of
  34. information needed to reconstruct the frame\-state for each instruction
  35. in a procedure. For dynamically generated code, the runtime code
  36. generator must use the dynamic unwind\-info interface provided by
  37. libunwind
  38. to supply the equivalent information. This manual
  39. page describes the format of this information in detail.
  40. .PP
  41. For the purpose of this discussion, a \fIprocedure\fP
  42. is defined to
  43. be an arbitrary piece of \fIcontiguous\fP
  44. code. Normally, each
  45. procedure directly corresponds to a function in the source\-language
  46. but this is not strictly required. For example, a runtime
  47. code\-generator could translate a given function into two separate
  48. (discontiguous) procedures: one for frequently\-executed (hot) code and
  49. one for rarely\-executed (cold) code. Similarly, simple
  50. source\-language functions (usually leaf functions) may get translated
  51. into code for which the default unwind\-conventions apply and for such
  52. code, it is not strictly necessary to register dynamic unwind\-info.
  53. .PP
  54. A procedure logically consists of a sequence of \fIregions\fP\&.
  55. Regions are nested in the sense that the frame state at the end of one
  56. region is, by default, assumed to be the frame state for the next
  57. region. Each region is thought of as being divided into a
  58. \fIprologue\fP,
  59. a \fIbody\fP,
  60. and an \fIepilogue\fP\&.
  61. Each of them
  62. can be empty. If non\-empty, the prologue sets up the frame state for
  63. the body. For example, the prologue may need to allocate some space
  64. on the stack and save certain callee\-saved registers. The body
  65. performs the actual work of the procedure but does not change the
  66. frame state in any way. If non\-empty, the epilogue restores the
  67. previous frame state and as such it undoes or cancels the effect of
  68. the prologue. In fact, a single epilogue may undo the effect of the
  69. prologues of several (nested) regions.
  70. .PP
  71. We should point out that even though the prologue, body, and epilogue
  72. are logically separate entities, optimizing code\-generators will
  73. generally interleave instructions from all three entities. For this
  74. reason, the dynamic unwind\-info interface of libunwind
  75. makes no
  76. distinction whatsoever between prologue and body. Similarly, the
  77. exact set of instructions that make up an epilogue is also irrelevant.
  78. The only point in the epilogue that needs to be described explicitly
  79. by the dynamic unwind\-info is the point at which the stack\-pointer
  80. gets restored. The reason this point needs to be described is that
  81. once the stack\-pointer is restored, all values saved in the
  82. deallocated portion of the stack frame become invalid and hence
  83. libunwind
  84. needs to know about it. The portion of the frame
  85. state not saved on the stack is assume to remain valid through the end
  86. of the region. For this reason, there is usually no need to describe
  87. instructions which restore the contents of callee\-saved registers.
  88. .PP
  89. Within a region, each instruction that affects the frame state in some
  90. fashion needs to be described with an operation descriptor. For this
  91. purpose, each instruction in the region is assigned a unique index.
  92. Exactly how this index is derived depends on the architecture. For
  93. example, on RISC and EPIC\-style architecture, instructions have a
  94. fixed size so it\&'s possible to simply number the instructions. In
  95. contrast, most CISC use variable\-length instruction encodings, so it
  96. is usually necessary to use a byte\-offset as the index. Given the
  97. instruction index, the operation descriptor specifies the effect of
  98. the instruction in an abstract manner. For example, it might express
  99. that the instruction stores calle\-saved register r1
  100. at offset 16
  101. in the stack frame.
  102. .PP
  103. .SH PROCEDURES
  104. .PP
  105. A runtime code\-generator registers the dynamic unwind\-info of a
  106. procedure by setting up a structure of type unw_dyn_info_t
  107. and calling _U_dyn_register(),
  108. passing the address of the
  109. structure as the sole argument. The members of the
  110. unw_dyn_info_t
  111. structure are described below:
  112. .TP
  113. void *next
  114. Private to libunwind\&.
  115. Must not be used
  116. by the application.
  117. .TP
  118. void *prev
  119. Private to libunwind\&.
  120. Must not be used
  121. by the application.
  122. .TP
  123. unw_word_t start_ip
  124. The start\-address of the
  125. instructions of the procedure (remember: procedure are defined to be
  126. contiguous pieces of code, so a single code\-range is sufficient).
  127. .TP
  128. unw_word_t end_ip
  129. The end\-address of the
  130. instructions of the procedure (non\-inclusive, that is,
  131. end_ip\-start_ip
  132. is the size of the procedure in
  133. bytes).
  134. .TP
  135. unw_word_t gp
  136. The global\-pointer value in use
  137. for this procedure. The exact meaing of the global\-pointer is
  138. architecture\-specific and on some architecture, it is not used at
  139. all.
  140. .TP
  141. int32_t format
  142. The format of the unwind\-info.
  143. This member can be one of UNW_INFO_FORMAT_DYNAMIC,
  144. UNW_INFO_FORMAT_TABLE,
  145. or
  146. UNW_INFO_FORMAT_REMOTE_TABLE\&.
  147. .TP
  148. union u
  149. This union contains one sub\-member
  150. structure for every possible unwind\-info format:
  151. .RS
  152. .TP
  153. unw_dyn_proc_info_t pi
  154. This member is used
  155. for format UNW_INFO_FORMAT_DYNAMIC\&.
  156. .TP
  157. unw_dyn_table_info_t ti
  158. This member is used
  159. for format UNW_INFO_FORMAT_TABLE\&.
  160. .TP
  161. unw_dyn_remote_table_info_t rti
  162. This member
  163. is used for format UNW_INFO_FORMAT_REMOTE_TABLE\&.
  164. .RE
  165. .RS
  166. .PP
  167. The format of these sub\-members is described in detail below.
  168. .RE
  169. .PP
  170. .SS PROC\-INFO FORMAT
  171. .PP
  172. This is the preferred dynamic unwind\-info format and it is generally
  173. the one used by full\-blown runtime code\-generators. In this format,
  174. the details of a procedure are described by a structure of type
  175. unw_dyn_proc_info_t\&.
  176. This structure contains the following
  177. members:
  178. .PP
  179. .RE
  180. .TP
  181. unw_word_t name_ptr
  182. The address of a
  183. (human\-readable) name of the procedure or 0 if no such name is
  184. available. If non\-zero, The string stored at this address must be
  185. ASCII NUL terminated. For source languages that use name\-mangling
  186. (such as C++ or Java) the string stored at this address should be
  187. the \fIdemangled\fP
  188. version of the name.
  189. .PP
  190. .TP
  191. unw_word_t handler
  192. The address of the
  193. personality\-routine for this procedure. Personality\-routines are
  194. used in conjunction with exception handling. See the C++ ABI draft
  195. (http://www.codesourcery.com/cxx\-abi/) for an overview and a
  196. description of the personality routine. If the procedure has no
  197. personality routine, handler
  198. must be set to 0.
  199. .PP
  200. .TP
  201. uint32_t flags
  202. A bitmask of flags. At the
  203. moment, no flags have been defined and this member must be
  204. set to 0.
  205. .PP
  206. .TP
  207. unw_dyn_region_info_t *regions
  208. A NULL\-terminated
  209. linked list of region\-descriptors. See section ``Region
  210. descriptors\&'' below for more details.
  211. .PP
  212. .SS TABLE\-INFO FORMAT
  213. .PP
  214. This format is generally used when the dynamically generated code was
  215. derived from static code and the unwind\-info for the dynamic and the
  216. static versions is identical. For example, this format can be useful
  217. when loading statically\-generated code into an address\-space in a
  218. non\-standard fashion (i.e., through some means other than
  219. dlopen()).
  220. In this format, the details of a group of procedures
  221. is described by a structure of type unw_dyn_table_info\&.
  222. This structure contains the following members:
  223. .PP
  224. .TP
  225. unw_word_t name_ptr
  226. The address of a
  227. (human\-readable) name of the procedure or 0 if no such name is
  228. available. If non\-zero, The string stored at this address must be
  229. ASCII NUL terminated. For source languages that use name\-mangling
  230. (such as C++ or Java) the string stored at this address should be
  231. the \fIdemangled\fP
  232. version of the name.
  233. .PP
  234. .TP
  235. unw_word_t segbase
  236. The segment\-base value
  237. that needs to be added to the segment\-relative values stored in the
  238. unwind\-info. The exact meaning of this value is
  239. architecture\-specific.
  240. .PP
  241. .TP
  242. unw_word_t table_len
  243. The length of the
  244. unwind\-info (table_data)
  245. counted in units of words
  246. (unw_word_t).
  247. .PP
  248. .TP
  249. unw_word_t table_data
  250. A pointer to the actual
  251. data encoding the unwind\-info. The exact format is
  252. architecture\-specific (see architecture\-specific sections below).
  253. .PP
  254. .SS REMOTE TABLE\-INFO FORMAT
  255. .PP
  256. The remote table\-info format has the same basic purpose as the regular
  257. table\-info format. The only difference is that when libunwind
  258. uses the unwind\-info, it will keep the table data in the target
  259. address\-space (which may be remote). Consequently, the type of the
  260. table_data
  261. member is unw_word_t
  262. rather than a pointer.
  263. This implies that libunwind
  264. will have to access the table\-data
  265. via the address\-space\&'s access_mem()
  266. call\-back, rather than
  267. through a direct memory reference.
  268. .PP
  269. From the point of view of a runtime\-code generator, the remote
  270. table\-info format offers no advantage and it is expected that such
  271. generators will describe their procedures either with the proc\-info
  272. format or the normal table\-info format. The main reason that the
  273. remote table\-info format exists is to enable the
  274. address\-space\-specific find_proc_info()
  275. callback (see
  276. unw_create_addr_space(3))
  277. to return unwind tables whose
  278. data remains in remote memory. This can speed up unwinding (e.g., for
  279. a debugger) because it reduces the amount of data that needs to be
  280. loaded from remote memory.
  281. .PP
  282. .SH REGIONS DESCRIPTORS
  283. .PP
  284. A region descriptor is a variable length structure that describes how
  285. each instruction in the region affects the frame state. Of course,
  286. most instructions in a region usualy do not change the frame state and
  287. for those, nothing needs to be recorded in the region descriptor. A
  288. region descriptor is a structure of type
  289. unw_dyn_region_info_t
  290. and has the following members:
  291. .TP
  292. unw_dyn_region_info_t *next
  293. A pointer to the
  294. next region. If this is the last region, next
  295. is NULL\&.
  296. .TP
  297. int32_t insn_count
  298. The length of the region in
  299. instructions. Each instruction is assumed to have a fixed size (see
  300. architecture\-specific sections for details). The value of
  301. insn_count
  302. may be negative in the last region of a procedure
  303. (i.e., it may be negative only if next
  304. is NULL).
  305. A
  306. negative value indicates that the region covers the last \fIN\fP
  307. instructions of the procedure, where \fIN\fP
  308. is the absolute value
  309. of insn_count\&.
  310. .TP
  311. uint32_t op_count
  312. The (allocated) length of
  313. the op_count
  314. array.
  315. .TP
  316. unw_dyn_op_t op
  317. An array of dynamic unwind
  318. directives. See Section ``Dynamic unwind directives\&'' for a
  319. description of the directives.
  320. .PP
  321. A region descriptor with an insn_count
  322. of zero is an
  323. \fIempty region\fP
  324. and such regions are perfectly legal. In fact,
  325. empty regions can be useful to establish a particular frame state
  326. before the start of another region.
  327. .PP
  328. A single region list can be shared across multiple procedures provided
  329. those procedures share a common prologue and epilogue (their bodies
  330. may differ, of course). Normally, such procedures consist of a canned
  331. prologue, the body, and a canned epilogue. This could be described by
  332. two regions: one covering the prologue and one covering the epilogue.
  333. Since the body length is variable, the latter region would need to
  334. specify a negative value in insn_count
  335. such that
  336. libunwind
  337. knows that the region covers the end of the procedure
  338. (up to the address specified by end_ip).
  339. .PP
  340. The region descriptor is a variable length structure to make it
  341. possible to allocate all the necessary memory with a single
  342. memory\-allocation request. To facilitate the allocation of a region
  343. descriptors libunwind
  344. provides a helper routine with the
  345. following synopsis:
  346. .PP
  347. size_t
  348. _U_dyn_region_size(int
  349. op_count);
  350. .PP
  351. This routine returns the number of bytes needed to hold a region
  352. descriptor with space for op_count
  353. unwind directives. Note
  354. that the length of the op
  355. array does not have to match exactly
  356. with the number of directives in a region. Instead, it is sufficient
  357. if the op
  358. array contains at least as many entries as there are
  359. directives, since the end of the directives can always be indicated
  360. with the UNW_DYN_STOP
  361. directive.
  362. .PP
  363. .SH DYNAMIC UNWIND DIRECTIVES
  364. .PP
  365. A dynamic unwind directive describes how the frame state changes
  366. at a particular point within a region. The description is in
  367. the form of a structure of type unw_dyn_op_t\&.
  368. This
  369. structure has the following members:
  370. .TP
  371. int8_t tag
  372. The operation tag. Must be one
  373. of the unw_dyn_operation_t
  374. values described below.
  375. .TP
  376. int8_t qp
  377. The qualifying predicate that controls
  378. whether or not this directive is active. This is useful for
  379. predicated architecturs such as IA\-64 or ARM, where the contents of
  380. another (callee\-saved) register determines whether or not an
  381. instruction is executed (takes effect). If the directive is always
  382. active, this member should be set to the manifest constant
  383. _U_QP_TRUE
  384. (this constant is defined for all
  385. architectures, predicated or not).
  386. .TP
  387. int16_t reg
  388. The number of the register affected
  389. by the instruction.
  390. .TP
  391. int32_t when
  392. The region\-relative number of
  393. the instruction to which this directive applies. For example,
  394. a value of 0 means that the effect described by this directive
  395. has taken place once the first instruction in the region has
  396. executed.
  397. .TP
  398. unw_word_t val
  399. The value to be applied by the
  400. operation tag. The exact meaning of this value varies by tag. See
  401. Section ``Operation tags\&'' below.
  402. .PP
  403. It is perfectly legitimate to specify multiple dynamic unwind
  404. directives with the same when
  405. value, if a particular instruction
  406. has a complex effect on the frame state.
  407. .PP
  408. Empty regions by definition contain no actual instructions and as such
  409. the directives are not tied to a particular instruction. By
  410. convention, the when
  411. member should be set to 0, however.
  412. .PP
  413. There is no need for the dynamic unwind directives to appear
  414. in order of increasing when
  415. values. If the directives happen to
  416. be sorted in that order, it may result in slightly faster execution,
  417. but a runtime code\-generator should not go to extra lengths just to
  418. ensure that the directives are sorted.
  419. .PP
  420. IMPLEMENTATION NOTE: should libunwind
  421. implementations for
  422. certain architectures prefer the list of unwind directives to be
  423. sorted, it is recommended that such implementations first check
  424. whether the list happens to be sorted already and, if not, sort the
  425. directives explicitly before the first use. With this approach, the
  426. overhead of explicit sorting is only paid when there is a real benefit
  427. and if the runtime code\-generator happens to generated sorted lists
  428. naturally, the performance penalty is limited to a simple O(N) check.
  429. .PP
  430. .SS OPERATIONS TAGS
  431. .PP
  432. The possible operation tags are defined by enumeration type
  433. unw_dyn_operation_t
  434. which defines the following
  435. values:
  436. .PP
  437. .TP
  438. UNW_DYN_STOP
  439. Marks the end of the dynamic unwind
  440. directive list. All remaining entries in the op
  441. array of the
  442. region\-descriptor are ignored. This tag is guaranteed to have a
  443. value of 0.
  444. .PP
  445. .TP
  446. UNW_DYN_SAVE_REG
  447. Marks an instruction which saves
  448. register reg
  449. to register val\&.
  450. .PP
  451. .TP
  452. UNW_DYN_SPILL_FP_REL
  453. Marks an instruction which
  454. spills register reg
  455. to a frame\-pointer\-relative location. The
  456. frame\-pointer\-relative offset is given by the value stored in member
  457. val\&.
  458. See the architecture\-specific sections for a description
  459. of the stack frame layout.
  460. .PP
  461. .TP
  462. UNW_DYN_SPILL_SP_REL
  463. Marks an instruction which
  464. spills register reg
  465. to a stack\-pointer\-relative location. The
  466. stack\-pointer\-relative offset is given by the value stored in member
  467. val\&.
  468. See the architecture\-specific sections for a description
  469. of the stack frame layout.
  470. .PP
  471. .TP
  472. UNW_DYN_ADD
  473. Marks an instruction which adds
  474. the constant value val
  475. to register reg\&.
  476. To add subtract
  477. a constant value, store the two\&'s\-complement of the value in
  478. val\&.
  479. The set of registers that can be specified for this tag
  480. is described in the architecture\-specific sections below.
  481. .PP
  482. .TP
  483. UNW_DYN_POP_FRAMES
  484. .PP
  485. .TP
  486. UNW_DYN_LABEL_STATE
  487. .PP
  488. .TP
  489. UNW_DYN_COPY_STATE
  490. .PP
  491. .TP
  492. UNW_DYN_ALIAS
  493. .PP
  494. unw_dyn_op_t
  495. .PP
  496. _U_dyn_op_save_reg();
  497. _U_dyn_op_spill_fp_rel();
  498. _U_dyn_op_spill_sp_rel();
  499. _U_dyn_op_add();
  500. _U_dyn_op_pop_frames();
  501. _U_dyn_op_label_state();
  502. _U_dyn_op_copy_state();
  503. _U_dyn_op_alias();
  504. _U_dyn_op_stop();
  505. .PP
  506. .SH IA\-64 SPECIFICS
  507. .PP
  508. \- meaning of segbase member in table\-info/table\-remote\-info format
  509. \- format of table_data in table\-info/table\-remote\-info format
  510. \- instruction size: each bundle is counted as 3 instructions, regardless
  511. of template (MLX)
  512. \- describe stack\-frame layout, especially with regards to sp\-relative
  513. and fp\-relative addressing
  514. \- UNW_DYN_ADD can only add to ``sp\&'' (always a negative value); use
  515. POP_FRAMES otherwise
  516. .PP
  517. .SH SEE ALSO
  518. .PP
  519. libunwind(3),
  520. _U_dyn_register(3),
  521. _U_dyn_cancel(3)
  522. .PP
  523. .SH AUTHOR
  524. .PP
  525. David Mosberger\-Tang
  526. .br
  527. Email: \fBdmosberger@gmail.com\fP
  528. .br
  529. WWW: \fBhttp://www.nongnu.org/libunwind/\fP\&.
  530. .\" NOTE: This file is generated, DO NOT EDIT.