2000-01-17 23:45:24 +08:00
|
|
|
// name-finder.h - Convert addresses to names
|
|
|
|
|
2002-02-08 03:25:28 +08:00
|
|
|
/* Copyright (C) 2000, 2002 Free Software Foundation, Inc
|
2000-01-17 23:45:24 +08:00
|
|
|
|
|
|
|
This file is part of libgcj.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Andrew Haley <aph@cygnus.com>
|
|
|
|
* @date Jan 6 2000
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gcj/cni.h>
|
|
|
|
#include <jvm.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2002-02-07 12:37:00 +08:00
|
|
|
|
2002-02-08 03:25:28 +08:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
2000-05-31 07:26:02 +08:00
|
|
|
#include <sys/wait.h>
|
2002-02-08 03:25:28 +08:00
|
|
|
#endif
|
2000-01-17 23:45:24 +08:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2002-07-12 20:52:44 +08:00
|
|
|
#include <java/lang/StackTraceElement.h>
|
|
|
|
|
2000-01-17 23:45:24 +08:00
|
|
|
/* _Jv_name_finder is a class wrapper around a mechanism that can
|
|
|
|
convert addresses of methods to their names and the names of files
|
|
|
|
in which they appear. */
|
|
|
|
|
|
|
|
class _Jv_name_finder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
_Jv_name_finder (char *executable);
|
|
|
|
~_Jv_name_finder ()
|
|
|
|
{
|
|
|
|
#if defined (HAVE_PIPE) && defined (HAVE_FORK)
|
2002-03-24 00:14:28 +08:00
|
|
|
myclose (f_pipe[0]);
|
|
|
|
myclose (f_pipe[1]);
|
|
|
|
myclose (b_pipe[0]);
|
|
|
|
myclose (b_pipe[1]);
|
|
|
|
if (b_pipe_fd != NULL)
|
|
|
|
fclose (b_pipe_fd);
|
|
|
|
|
2002-07-12 20:52:44 +08:00
|
|
|
myclose (f2_pipe[0]);
|
|
|
|
myclose (f2_pipe[1]);
|
|
|
|
myclose (b2_pipe[0]);
|
|
|
|
myclose (b2_pipe[1]);
|
|
|
|
if (b2_pipe_fd != NULL)
|
|
|
|
fclose (b2_pipe_fd);
|
|
|
|
|
2002-03-24 00:14:28 +08:00
|
|
|
if (pid >= 0)
|
|
|
|
{
|
|
|
|
int wstat;
|
|
|
|
// We don't care about errors here.
|
|
|
|
waitpid (pid, &wstat, 0);
|
|
|
|
}
|
2002-07-12 20:52:44 +08:00
|
|
|
|
|
|
|
if (pid2 >= 0)
|
|
|
|
{
|
|
|
|
int wstat;
|
|
|
|
// We don't care about errors here.
|
|
|
|
waitpid (pid2, &wstat, 0);
|
|
|
|
}
|
2000-01-17 23:45:24 +08:00
|
|
|
#endif
|
2000-05-31 07:26:02 +08:00
|
|
|
}
|
2000-01-17 23:45:24 +08:00
|
|
|
|
|
|
|
/* Given a pointer to a function or method, try to convert it into a
|
|
|
|
name and the appropriate line and source file. The caller passes
|
|
|
|
the code pointer in p.
|
|
|
|
|
2002-07-12 20:52:44 +08:00
|
|
|
Returns NULL if the lookup fails. Even if this happens, the field
|
|
|
|
hex will have been correctly filled in with the pointer. */
|
2000-01-17 23:45:24 +08:00
|
|
|
|
2002-07-12 20:52:44 +08:00
|
|
|
java::lang::StackTraceElement* lookup (void *p);
|
2000-01-17 23:45:24 +08:00
|
|
|
|
|
|
|
char hex[sizeof (void *) * 2 + 5];
|
|
|
|
|
|
|
|
private:
|
|
|
|
void toHex (void *p);
|
2002-07-12 20:52:44 +08:00
|
|
|
java::lang::StackTraceElement* createStackTraceElement(char *s, char *f);
|
2000-01-17 23:45:24 +08:00
|
|
|
#if defined (HAVE_PIPE) && defined (HAVE_FORK)
|
2002-07-12 20:52:44 +08:00
|
|
|
pid_t pid, pid2;
|
|
|
|
int f_pipe[2], b_pipe[2], f2_pipe[2], b2_pipe[2];
|
|
|
|
FILE *b_pipe_fd, *b2_pipe_fd;
|
|
|
|
int demangling_error, lookup_error;
|
2002-03-24 00:14:28 +08:00
|
|
|
|
|
|
|
// Close a descriptor only if it has not been closed.
|
|
|
|
void myclose (int fd)
|
|
|
|
{
|
|
|
|
if (fd != -1)
|
|
|
|
close (fd);
|
|
|
|
}
|
|
|
|
|
2000-01-17 23:45:24 +08:00
|
|
|
#endif
|
|
|
|
};
|