| 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 <[email protected]>
|
|---|
| 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 | myclose (f_pipe[0]);
|
|---|
| 44 | myclose (f_pipe[1]);
|
|---|
| 45 | myclose (b_pipe[0]);
|
|---|
| 46 | myclose (b_pipe[1]);
|
|---|
| 47 | if (b_pipe_fd != NULL)
|
|---|
| 48 | fclose (b_pipe_fd);
|
|---|
| 49 |
|
|---|
| 50 | if (pid >= 0)
|
|---|
| 51 | {
|
|---|
| 52 | int wstat;
|
|---|
| 53 | // We don't care about errors here.
|
|---|
| 54 | waitpid (pid, &wstat, 0);
|
|---|
| 55 | }
|
|---|
| 56 | #endif
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /* Given a pointer to a function or method, try to convert it into a
|
|---|
| 60 | name and the appropriate line and source file. The caller passes
|
|---|
| 61 | the code pointer in p.
|
|---|
| 62 |
|
|---|
| 63 | Returns false if the lookup fails. Even if this happens, the field
|
|---|
| 64 | hex will have been correctly filled in with the pointer.
|
|---|
| 65 |
|
|---|
| 66 | The other fields are method_name and file_name, which lookup will
|
|---|
| 67 | attempt to fill appropriately. If the lookup has failed, these
|
|---|
| 68 | fields contain garbage.*/
|
|---|
| 69 | bool lookup (void *p);
|
|---|
| 70 |
|
|---|
| 71 | char method_name[1024];
|
|---|
| 72 | char file_name[1024];
|
|---|
| 73 | char hex[sizeof (void *) * 2 + 5];
|
|---|
| 74 |
|
|---|
| 75 | private:
|
|---|
| 76 | void toHex (void *p);
|
|---|
| 77 | #if defined (HAVE_PIPE) && defined (HAVE_FORK)
|
|---|
| 78 | pid_t pid;
|
|---|
| 79 | int f_pipe[2], b_pipe[2];
|
|---|
| 80 | FILE *b_pipe_fd;
|
|---|
| 81 | int error;
|
|---|
| 82 |
|
|---|
| 83 | // Close a descriptor only if it has not been closed.
|
|---|
| 84 | void myclose (int fd)
|
|---|
| 85 | {
|
|---|
| 86 | if (fd != -1)
|
|---|
| 87 | close (fd);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | #endif
|
|---|
| 91 | };
|
|---|