[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libunwind-devel] unw_getcontext on Mac OS X 10.6

From: Marc Paterno
Subject: [Libunwind-devel] unw_getcontext on Mac OS X 10.6
Date: Wed, 24 Feb 2010 10:36:59 -0600


I am using the version of libunwind that ships with Mac OS X 10.6.

The documentation for unw_getcontext() says that it returns only 0 or -1. 
However, in a simple test program, I find that unw_getcontext is always 
returning the value 2440 (0x988). The source of the program is appended below.

If I ignore the return value, it would seem that unw_getcontext() has 
succeeded; at least the unw_context_t struct that it has initialized is 
acceptable for use in getting a cursor with unw_init_local.

Is the apparent failure of unw_getcontext() spurious in that it is OK to use 
the resulting unw_context_t struct?

What does the status code of 0x988 mean?

Any guidance would be most appreciated.

best regards,

Dr. Marc Paterno
Fermi National Accelerator Laboratory

#include <iostream>

// Define UNW_LOCAL_ONLY before including libunwind.h to use the fast version
// of the unwinding (faster than the version that supports remote unwinding).

#include "libunwind.h"

int work() {
  // Get the current machine state.
  unw_context_t uc;
  int rc;
  rc = unw_getcontext(&uc);
  if (rc != 0) {
    std::cerr << "unw_getcontext failed: rc = " << rc << "; proceeding 

  // Initialize curser for local unwinding.
  unw_cursor_t cursor;
  rc = unw_init_local(&cursor, &uc);
  if (rc != 0) {
    std::cerr << "unw_init_local failed: rc = " << rc << "; proceeding 

  // Step through the stack frames and print out the information as you go.
  // When unw_step() is 0, the end of chain has been reached.
  while (unw_step(&cursor) > 0) {
    // Read ip register.
    unw_word_t ip;
    rc = unw_get_reg(&cursor, UNW_REG_IP, &ip);
    if (rc != 0) {
      std::cerr << "unw_get_reg failed: rc = " << rc << "; stopping unwind\n";
    void* address = (char *) ip - 4;
    std::cerr << "Got address: " << address << std::endl;
  std::cerr << "Done\n";
  return 0;

int main() {
  int rc = work();
  return rc;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]