#ifdef __VAX
# error AXP/IA64/x86_64 specific code
#endif
#define __NEW_STARLET 1
#pragma optimize level=0
#include <stdio.h>
#include <stdlib.h>
#include <ssdef.h>
#include <stsdef.h>
#include <descrip.h>
#include <string.h>
#include <libicb.h>
#include <tbkdef.h>
#include <tbk$routines.h>
#include <lib$routines.h>
#include "errchk.h"
#ifdef __ia64
# define lib$get_curr_invo_context lib$i64_get_curr_invo_context
# define lib$get_prev_invo_context lib$i64_get_prev_invo_context
#endif
#ifdef __x86_64
# define lib$get_curr_invo_context lib$x86_get_curr_invo_context
# define lib$get_prev_invo_context lib$x86_get_prev_invo_context
#endif
static void trace_calls (void) {
static INVO_CONTEXT_BLK icb;
static unsigned __int64 the_pc;
static unsigned __int64 flags = 0;
static unsigned int line;
static int finished;
static int r0_status;
static char image[512];
static char module[512];
static char routine[512];
static char spaces[] = " ";
static struct dsc$descriptor_s image_d = { sizeof (image) - 1,
DSC$K_DTYPE_T,
DSC$K_CLASS_S,
image };
static struct dsc$descriptor_s module_d = { sizeof (module) - 1,
DSC$K_DTYPE_T,
DSC$K_CLASS_S,
module };
static struct dsc$descriptor_s routine_d = { sizeof (routine) - 1,
DSC$K_DTYPE_T,
DSC$K_CLASS_S,
routine };
static TBK_API_PARAM tbkitms;
(void)memset (&tbkitms, 0, sizeof (TBK_API_PARAM));
tbkitms.tbk$w_length = TBK$K_LENGTH;
tbkitms.tbk$b_version = TBK$K_VERSION;
tbkitms.tbk$pq_image_desc = (struct _descriptor *)&image_d;
tbkitms.tbk$pq_module_desc = (struct _descriptor *)&module_d;
tbkitms.tbk$pq_routine_desc = (struct _descriptor *)&routine_d;
tbkitms.tbk$pq_listing_lineno = &line;
tbkitms.tbk$pq_symbolize_flags = &flags;
#ifdef __ia64
r0_status = lib$i64_init_invo_context (&icb, LIBICB$K_INVO_CONTEXT_VERSION);
errchk_sig (r0_status);
#endif
#ifdef __x86_64
r0_status = lib$x86_init_invo_context (&icb, LIBICB$K_INVO_CONTEXT_VERSION);
errchk_sig (r0_status);
#endif
lib$get_curr_invo_context (&icb);
(void)printf ("Image "
"Module "
"Routine "
"Line abs PC\n");
finished = FALSE;
while (!finished) {
#ifdef __alpha
tbkitms.tbk$q_faulting_pc = icb.libicb$q_program_counter;
tbkitms.tbk$q_faulting_fp = icb.libicb$q_ireg[29];
#endif
#ifdef __ia64
tbkitms.tbk$q_faulting_pc = (unsigned __int64)icb.libicb$ih_pc;
#endif
#ifdef __x86_64
tbkitms.tbk$q_faulting_pc = (unsigned __int64)icb.libicb$ih_ip;
#endif
#ifdef __alpha
r0_status = tbk$alpha_symbolize ((unsigned int *)&tbkitms);
#endif
#ifdef __ia64
r0_status = tbk$i64_symbolize (&tbkitms);
#endif
errchk_stop (r0_status);
if (image_d.dsc$w_length > strlen (spaces)) {
image_d.dsc$w_length = strlen (spaces);
}
if (module_d.dsc$w_length > strlen (spaces)) {
module_d.dsc$w_length = strlen (spaces);
}
if (routine_d.dsc$w_length > strlen (spaces)) {
routine_d.dsc$w_length = strlen (spaces);
}
#ifdef __alpha
the_pc = icb.libicb$q_program_counter;
#endif
#ifdef __ia64
the_pc = (unsigned __int64)icb.libicb$ih_pc;
#endif
#ifdef __x86_64
the_pc = (unsigned __int64)icb.libicb$ih_ip;
#endif
(void)printf ("%-.*s%s %-.*s%s %-.*s%s %8ld %16.16LX\n",
image_d.dsc$w_length,
image_d.dsc$a_pointer,
&spaces[image_d.dsc$w_length],
module_d.dsc$w_length,
module_d.dsc$a_pointer,
&spaces[module_d.dsc$w_length],
routine_d.dsc$w_length,
routine_d.dsc$a_pointer,
&spaces[routine_d.dsc$w_length],
line,
the_pc);
r0_status = lib$get_prev_invo_context (&icb);
if (!$VMS_STATUS_SUCCESS (r0_status)) {
finished = TRUE;
} else {
if (icb.libicb$v_bottom_of_stack) {
finished = TRUE;
}
}
}
#ifdef __ia64
r0_status = lib$i64_prev_invo_end (&icb);
errchk_sig (r0_status);
#endif
}
static void function2 (void) {
trace_calls ();
}
static void function1 (void) {
function2 ();
}
int main (void) {
function1();
}