[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::axp-developer

Title:Alpha Developer Support
Notice:[email protected], 800-332-4786
Moderator:HYDRA::SYSTEM
Created:Mon Jun 06 1994
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3722
Total number of notes:11359

3566.0. "tibco" by HYDRA::AXPDEVELOPER (Alpha Developer support) Wed Apr 30 1997 17:03

    Company Name :  tibco
    Contact Name :  Marian Jones
    Phone        :  415/846-5018
    Fax          :  
    Email        :  [email protected]
    Date/Time in :  30-APR-1997 16:02:24
    Entered by   :  Chuck Newman
    SPE center   :  MRO

    Category     :  vms
    OS Version   :  
    System H/W   :  Alpha


    Brief Description of Problem:
    -----------------------------

Software vendor writes:
--------------------------------------------------------------------------------
Do you have example code to illustrate the use of traceback and condition
handling in a threaded process ?  I have a simple program which just starts
some threads and then exits.  One of the tests that I run is to put an
exception (usually a divide by zero) in this program to verify that our
exception handler is called and that we have some traceback.  It seems that we
can have either one or the other but not both.  If the exception is in the main
thread, the exception handler is not called but we get traceback and if the
exception is in a child thread our exception handler is called but we cannot
get any traceback.  I have included the output from both tests.

My question is can we have both the exception handler triggered and traceback
displayed whether the exception is in the main or child thread ?  If not, then
is it configurable.  In other words, can we read an environment variable and
depending on its value, use traceback or an exception handler ? 

Also, if you have any example code to illustrate this please e-mail it to me. 

Many Thanks,

Marian Jones
e-mail:  [email protected]		Phone: 415-846-5018

EXCEPTION IN THE MAIN THREAD
---------------------------
 !!!!!!!!!!About to test div by zero !!!!!!!!!!!!!
%SYSTEM-F-INTDIV, arithmetic trap, integer divide by zero at PC=8048EA98,PS=0000001B
%TRACE-F-TRACEBACK, symbolic stack dump follows
 Image Name   Module Name     Routine Name    Line Number  rel PC abs PC
                                                       	0 8048EA98  8048EA98
 BTHTEST_RV   BTHTEST         main                   4482 00000C48  00030C48
 BTHTEST_RV   BTHTEST         __main                    0 00000090  00030090
                                                        0 83B04170  83B04170


EXCEPTION IN THE CHILD THREAD
---------------------------
 !!!!!!!!!!About to test div by zero !!!!!!!!!!!!!
*
* The TIBCO exception handler was triggered.
*
%CMA-F-EXCCOP, exception raised; VMS condition code follows
-SYSTEM-F-INTDIV, arithmetic trap, integer divide by zero at PC=8048EA98, PS=0000001B


-- 
Marian Jones
TIBCO Inc

[email protected]
T.RTitleUserPersonal
Name
DateLines
3566.1Note sent to developerHYDRA::NEWMANChuck Newman, 508/467-5499 (DTN 297), MRO1-3/F26Fri May 02 1997 14:4123
Marian --

I agree that the default behavior is different depending on whether the failure
is in a thread or not, but I'm not quite sure exactly what behavior you want.
By "default" I mean what happens when you have not specified your own condition
handler.

In your MAIL you said that you want to have a traceback and also have your
condition handler execute.  To the best of my knowledge this is not something
you can get, independant of whether you're using threads or not.

There are routines to help you walk the frames, but I don't know of any
supported way to get the symbol information (i.e., routine names and line
numbers).  These routines are LIB$GET_CURRENT_INVO_CONTEXT and friends.

And no, I don't know any way to force a traceback from a thread.

Make sure you read the section titled "Using the DECthreads Exception Package"
in the "Guide to DECthreads" manual on the Documentation CD that ships with
OpenVMS.


                                                                -- Chuck Newman
3566.2A little more information (not yet sent to developer)HYDRA::NEWMANChuck Newman, 508/467-5499 (DTN 297), MRO1-3/F26Fri May 02 1997 18:4341
Well, it *IS* possible to get a traceback without dieing -- but I haven't yet
been able to do it from a thread.  Here's the test program I'm working on:

$ cc/REENTRANCY=MULTITHREAD
$ link a,a/opt

(a.opt = sys$share:CMA$OPEN_RTL/shar)

#include <pthread.h>
#include <stdio.h>
#include <lib$routines.h>
static void a_function(int *);
main()
{
pthread_t a_thread;
volatile int doit=0;

printf("Before thread:  traceback\n");
lib$signal(0);
printf("traced back\n");
pthread_create(&a_thread, pthread_attr_default, (void * ((*)(void
*)))(&a_function), (void *)(&doit));
while (doit == 0) ;
printf("After thread:  traceback\n");
lib$signal(0);
printf("traced back\n");
}

static void a_function(int *doit)
{
printf("in a thread:  traceback\n");
lib$signal(0);
printf("traced back\n");
*doit = 1;
}




Another option would be to signal ss$_debug, and tell the debugger to SHOW
CALLS;GO, but that would leave the problem of the image exiting to the debugger.
3566.3The following worked on V7.1 -- sent to developerHYDRA::NEWMANChuck Newman, 508/467-5499 (DTN 297), MRO1-3/F26Tue May 27 1997 15:41113
Marion --

The following works on OpenVMS Alpha V7.1.  I hope it is close to what you need.

$ cc/REENTRANCY=MULTITHREAD a
$ link a,a/opt

(a.opt = sys$share:CMA$OPEN_RTL/shar)

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <ssdef.h>
#include <lib$routines.h>
static void a_function(int *);
static int value1, value2, value3;
main(int argc, char *argv[])
{
pthread_t a_thread;
pthread_attr_t pthread_attr;
volatile int doit=0;

if (argc <= 1)
 {
  value1 = 0;
  value2 = 0;
  value3 = 0;
 }
else
 {
  value1 = atoi(argv[1]);
  if (argc == 3)
   {
    value2 = atoi(argv[2]);
    if (argc == 4)
     {
      value3 = atoi(argv[3]);
     }
    else
     {
      value3 = 0;
     }
   }
  else
   {
    value2 = 0;
    value3 = 0;
   }
 }

pthread_attr_init(&pthread_attr);

printf("Before thread:  traceback\n");
lib$signal(value1);
printf("traced back\n");
pthread_create(&a_thread, &pthread_attr, (void * ((*)(void *)))(&a_function),
(void *)(&doit));
while (doit == 0) ;
printf("After thread:  traceback\n");
lib$signal(value2);
printf("traced back\n");
}

static void a_function(int *doit)
{
printf("in a thread:  traceback\n");
                    PTHREAD_TRY_NP {
                        }
                    PTHREAD_CATCH_ALL_NP {
                        PTHREAD_RERAISE_NP;
                        }
                    PTHREAD_ENDTRY_NP
lib$signal(value3);
printf("traced back\n");
*doit = 1;
}




$ run a
Before thread:  traceback
%NONAME-W-NOMSG, Message number 00000000
%TRACE-W-NOMSG, Message number 00098048
  image    module    routine             line      rel PC           abs PC
 A  A  main                             12996 0000000000000220 0000000000020220
 A  A  __main                               0 00000000000000C0 00000000000200C0
 PTHREAD$RTL                                0 000000000004C148 000000000008E148
 PTHREAD$RTL                                0 0000000000030664 0000000000072664
                                            0 FFFFFFFF82E8D0D8 FFFFFFFF82E8D0D8
traced back
in a thread:  traceback
%NONAME-W-NOMSG, Message number 00000000
%TRACE-W-NOMSG, Message number 00098048
  image    module    routine             line      rel PC           abs PC
 A  A  a_function                       13014 0000000000000414 0000000000020414
 PTHREAD$RTL                                0 000000000004C148 000000000008E148
 PTHREAD$RTL                                0 000000000003D294 000000000007F294
                                            0 0000000000000000 0000000000000000
 PTHREAD$RTL                                                 ?                ?
                                            0 FFFFFFFF82E8D0D8 FFFFFFFF82E8D0D8
traced back
After thread:  traceback
%NONAME-W-NOMSG, Message number 00000000
%TRACE-W-NOMSG, Message number 00098048
  image    module    routine             line      rel PC           abs PC
 A  A  main                             13001 000000000000029C 000000000002029C
 A  A  __main                               0 00000000000000C0 00000000000200C0
 PTHREAD$RTL                                0 000000000004C148 000000000008E148
 PTHREAD$RTL                                0 0000000000030664 0000000000072664
                                            0 FFFFFFFF82E8D0D8 FFFFFFFF82E8D0D8
traced back
$