3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 #define WIN32_LEAN_AND_MEAN
16 #include <sys/cygwin.h>
17 #include <cygwin/version.h>
21 struct option longopts
[] =
23 {"help", no_argument
, NULL
, '?'},
24 {"version", no_argument
, NULL
, 'V'},
25 {"usage", no_argument
, NULL
, 0},
26 {0, no_argument
, NULL
, 0}
28 const char *opts
= "?V";
30 __attribute__((noreturn
))
34 printf ("Usage: pldd [OPTION...] PID\n\n"
35 "List dynamic shared objects loaded into a process.\n\n"
36 " -?, --help Give this help list\n"
37 " --usage Give a short usage message\n"
38 " -V, --version Print program version\n");
42 __attribute__((noreturn
))
46 printf ("Usage: pldd [-?V] [--help] [--usage] [--version] PID\n");
50 __attribute__((noreturn
))
54 printf ("pldd (cygwin) %d.%d.%d\n"
55 "List dynamic shared objects loaded into process.\n"
56 "Copyright (C) 2012 Cygwin Authors\n\n"
57 "This program comes with NO WARRANTY, to the extent permitted by law.\n"
58 "You may redistribute copies of this program under the terms of\n"
59 "the Cygwin license. Please consult the CYGWIN_LICENSE file for details.\n",
60 CYGWIN_VERSION_DLL_MAJOR
/ 1000,
61 CYGWIN_VERSION_DLL_MAJOR
% 1000,
62 CYGWIN_VERSION_DLL_MINOR
);
66 __attribute__((noreturn
))
70 fprintf (stderr
, "Exactly one parameter with process ID required.\n"
71 "Try `pldd --help' or `pldd --usage' for more information.\n");
76 main (int argc
, char *argv
[])
78 int optch
, pid
, winpid
, i
;
79 char *pidfile
, *exefile
, *exename
;
82 HMODULE hModules
[1024];
85 while ((optch
= getopt_long (argc
, argv
, opts
, longopts
, &optind
)) != -1)
95 if (strcmp ("usage", longopts
[optind
].name
) == 0)
107 pid
= atoi (argv
[0]);
110 error (1, 0, "invalid process ID '%s'", argv
[0]);
112 pidfile
= (char *) malloc (32);
113 sprintf (pidfile
, "/proc/%d/winpid", pid
);
114 fd
= fopen (pidfile
, "rb");
116 error (1, ENOENT
, "cannot open /proc/%d", pid
);
117 fscanf (fd
, "%d", &winpid
);
120 exefile
= (char *) malloc (32);
121 exename
= (char *) malloc (MAX_PATH
);
122 sprintf (exefile
, "/proc/%d/exename", pid
);
123 fd
= fopen (exefile
, "rb");
125 error (1, ENOENT
, "cannot open /proc/%d", pid
);
126 fscanf (fd
, "%s", exename
);
129 hProcess
= OpenProcess (PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ
,
132 error (1, EPERM
, "cannot attach to process %d", pid
);
134 printf ("%d:\t%s\n", pid
, exename
);
136 EnumProcessModules (hProcess
, hModules
, sizeof (hModules
), &cbModules
);
137 /* start at 1 to skip the executable itself */
138 for (i
= 1; i
< (cbModules
/ sizeof (HMODULE
)); i
++)
140 TCHAR winname
[MAX_PATH
];
141 char posixname
[MAX_PATH
];
142 GetModuleFileNameEx (hProcess
, hModules
[i
], winname
, MAX_PATH
);
143 cygwin_conv_path (CCP_WIN_W_TO_POSIX
, winname
, posixname
, MAX_PATH
);
144 printf ("%s\n", posixname
);