OSDN Git Service

libjava:
[pf3gnuchains/gcc-fork.git] / libjava / include / name-finder.h
1 // name-finder.h - Convert addresses to names
2
3 /* Copyright (C) 2000, 2002  Free Software Foundation, Inc
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 /**
12  * @author Andrew Haley <aph@cygnus.com>
13  * @date Jan 6  2000
14  */
15
16 #include <gcj/cni.h>
17 #include <jvm.h>
18
19 #include <sys/types.h>
20
21 #ifdef HAVE_SYS_WAIT_H
22 #include <sys/wait.h>
23 #endif
24
25 #include <string.h>
26 #include <stdio.h>
27
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31
32 /* _Jv_name_finder is a class wrapper around a mechanism that can
33    convert addresses of methods to their names and the names of files
34    in which they appear. */
35
36 class _Jv_name_finder
37 {
38 public:  
39   _Jv_name_finder (char *executable);
40   ~_Jv_name_finder ()
41     {
42 #if defined (HAVE_PIPE) && defined (HAVE_FORK)
43       close (f_pipe[1]);
44       fclose (b_pipe_fd);
45
46       int wstat;
47       // We don't care about errors here.
48       waitpid (pid, &wstat, 0);
49 #endif
50     }
51
52 /* Given a pointer to a function or method, try to convert it into a
53    name and the appropriate line and source file.  The caller passes
54    the code pointer in p.
55
56    Returns false if the lookup fails.  Even if this happens, the field
57    hex will have been correctly filled in with the pointer. 
58
59    The other fields are method_name and file_name, which lookup will
60    attempt to fill appropriately.  If the lookup has failed, these
61    fields contain garbage.*/
62   bool lookup (void *p);
63
64   char method_name[1024];
65   char file_name[1024];
66   char hex[sizeof (void *) * 2 + 5];
67
68 private:
69   void toHex (void *p);
70 #if defined (HAVE_PIPE) && defined (HAVE_FORK)
71   pid_t pid;
72   int f_pipe[2], b_pipe[2];
73   FILE *b_pipe_fd;
74   int error;
75 #endif
76 };