2000-02-18 03:38:33 +08:00
|
|
|
/* strace.cc: system/windows tracing
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-08-03 03:26:01 +08:00
|
|
|
#include <ctype.h>
|
2005-01-13 06:40:46 +08:00
|
|
|
#include "cygerrno.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2002-01-29 10:02:03 +08:00
|
|
|
#include "perprocess.h"
|
|
|
|
#include "cygwin_version.h"
|
2002-08-02 00:20:31 +08:00
|
|
|
#include "cygthread.h"
|
2002-10-23 00:18:55 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2002-10-23 00:18:55 +08:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2005-12-30 04:46:34 +08:00
|
|
|
#include "child_info.h"
|
2015-07-20 04:38:30 +08:00
|
|
|
#include "sync.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2015-07-20 04:38:30 +08:00
|
|
|
#define PROTECT(x) {x[NT_MAX_PATH - 1] = '\0';}
|
|
|
|
#define CHECK(x) if (x[NT_MAX_PATH - 1] != '\0') \
|
|
|
|
{ small_printf ("array bound exceeded %d\n", __LINE__); \
|
|
|
|
ExitProcess (1); \
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-06-19 23:27:27 +08:00
|
|
|
class strace NO_COPY strace;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
#ifndef NOSTRACE
|
|
|
|
|
2010-04-01 02:06:02 +08:00
|
|
|
void
|
2011-11-24 10:17:55 +08:00
|
|
|
strace::activate (bool isfork)
|
2008-12-20 03:09:51 +08:00
|
|
|
{
|
2011-12-08 14:17:49 +08:00
|
|
|
if (!_active && being_debugged ())
|
2008-12-20 03:09:51 +08:00
|
|
|
{
|
|
|
|
char buf[30];
|
2015-07-20 04:38:30 +08:00
|
|
|
__small_sprintf (buf, "cYg%8x %lx %d",
|
|
|
|
_STRACE_INTERFACE_ACTIVATE_ADDR, &_active, isfork);
|
2008-12-20 03:09:51 +08:00
|
|
|
OutputDebugString (buf);
|
2011-11-25 05:36:53 +08:00
|
|
|
if (_active)
|
2005-12-30 04:46:34 +08:00
|
|
|
{
|
2011-11-25 05:36:53 +08:00
|
|
|
char pidbuf[80];
|
2015-07-20 04:38:30 +08:00
|
|
|
PWCHAR progname;
|
2011-11-25 05:36:53 +08:00
|
|
|
if (myself)
|
|
|
|
{
|
2015-07-20 04:38:30 +08:00
|
|
|
__small_sprintf (pidbuf, "(pid %d, ppid %d, windows pid %u)",
|
|
|
|
myself->pid, myself->ppid ?: 1,
|
|
|
|
GetCurrentProcessId ());
|
2011-11-25 05:36:53 +08:00
|
|
|
progname = myself->progname;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-20 04:38:30 +08:00
|
|
|
__small_sprintf (pidbuf, "(windows pid %u)",
|
|
|
|
GetCurrentProcessId ());
|
|
|
|
progname = global_progname;
|
2011-11-25 05:36:53 +08:00
|
|
|
}
|
|
|
|
prntf (1, NULL, "**********************************************");
|
|
|
|
prntf (1, NULL, "Program name: %W %s", progname, pidbuf);
|
|
|
|
prntf (1, NULL, "OS version: Windows %s", wincap.osname ());
|
|
|
|
prntf (1, NULL, "**********************************************");
|
2005-12-30 04:46:34 +08:00
|
|
|
}
|
2011-06-17 16:30:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
strace::dll_info ()
|
|
|
|
{
|
|
|
|
if (active ())
|
|
|
|
{
|
2002-01-29 10:02:03 +08:00
|
|
|
prntf (1, NULL, "App version: %d.%d, api: %d.%d",
|
|
|
|
user_data->dll_major, user_data->dll_minor,
|
|
|
|
user_data->api_major, user_data->api_minor);
|
|
|
|
prntf (1, NULL, "DLL version: %d.%d, api: %d.%d",
|
|
|
|
cygwin_version.dll_major, cygwin_version.dll_minor,
|
|
|
|
cygwin_version.api_major, cygwin_version.api_minor);
|
|
|
|
prntf (1, NULL, "DLL build: %s", cygwin_version.dll_build_date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-07 13:33:09 +08:00
|
|
|
int
|
2002-02-16 01:06:40 +08:00
|
|
|
strace::microseconds ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2018-11-27 20:47:02 +08:00
|
|
|
static LONGLONG process_start NO_COPY;
|
2018-12-01 05:39:57 +08:00
|
|
|
clk_monotonic_t *clk = (clk_monotonic_t *) get_clock (CLOCK_MONOTONIC);
|
2018-11-27 20:47:02 +08:00
|
|
|
|
|
|
|
if (!process_start)
|
2018-12-01 05:39:57 +08:00
|
|
|
process_start = clk->strace_usecs ();
|
|
|
|
return (int) (clk->strace_usecs () - process_start);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2022-06-07 00:00:45 +08:00
|
|
|
static int
|
2000-08-03 03:26:01 +08:00
|
|
|
getfunc (char *in_dst, const char *func)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
const char *pe;
|
|
|
|
char *dst = in_dst;
|
|
|
|
for (p = func; (pe = strchr (p, '(')); p = pe + 1)
|
|
|
|
if (isalnum ((int)pe[-1]) || pe[-1] == '_')
|
|
|
|
break;
|
2002-09-23 08:31:31 +08:00
|
|
|
else if (isspace ((int)pe[-1]))
|
2000-08-03 03:26:01 +08:00
|
|
|
{
|
|
|
|
pe--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!pe)
|
|
|
|
pe = strchr (func, '\0');
|
|
|
|
for (p = pe; p > func; p--)
|
|
|
|
if (p != pe && *p == ' ')
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*p == '*')
|
|
|
|
p++;
|
|
|
|
while (p < pe)
|
|
|
|
*dst++ = *p++;
|
|
|
|
|
|
|
|
*dst++ = ':';
|
|
|
|
*dst++ = ' ';
|
|
|
|
*dst = '\0';
|
|
|
|
|
|
|
|
return dst - in_dst;
|
|
|
|
}
|
|
|
|
|
2005-12-30 04:46:34 +08:00
|
|
|
static char *
|
|
|
|
mypid (char *buf)
|
|
|
|
{
|
|
|
|
if (myself && myself->pid)
|
|
|
|
__small_sprintf (buf, "%d", myself->pid);
|
|
|
|
else
|
2011-11-25 05:36:53 +08:00
|
|
|
__small_sprintf (buf, "(%d)", GetCurrentProcessId ());
|
2005-12-30 04:46:34 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* sprintf analog for use by output routines. */
|
2000-03-07 13:33:09 +08:00
|
|
|
int
|
2000-08-03 03:26:01 +08:00
|
|
|
strace::vsprntf (char *buf, const char *func, const char *infmt, va_list ap)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int count;
|
2000-02-28 13:05:33 +08:00
|
|
|
char fmt[80];
|
2003-12-08 06:37:12 +08:00
|
|
|
static NO_COPY bool nonewline = false;
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD err = GetLastError ();
|
2018-01-24 16:34:23 +08:00
|
|
|
const char *tn = mythreadname ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-03-07 13:33:09 +08:00
|
|
|
int microsec = microseconds ();
|
2000-02-18 03:38:33 +08:00
|
|
|
lmicrosec = microsec;
|
|
|
|
|
2010-05-18 22:30:51 +08:00
|
|
|
__small_sprintf (fmt, "%7d [%s] %s ", microsec, tn, "%W %s%s");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
SetLastError (err);
|
2000-08-03 03:26:01 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (nonewline)
|
2000-08-03 03:26:01 +08:00
|
|
|
count = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
|
|
|
{
|
2010-05-18 22:30:51 +08:00
|
|
|
PWCHAR pn = NULL;
|
2015-07-20 04:38:30 +08:00
|
|
|
WCHAR progname[NAME_MAX];
|
|
|
|
if (cygwin_finished_initializing && __progname)
|
|
|
|
{
|
|
|
|
char *p = strrchr (__progname, '/');
|
|
|
|
if (p)
|
|
|
|
++p;
|
|
|
|
else
|
|
|
|
p = __progname;
|
|
|
|
char *pe = strrchr (p, '.');
|
|
|
|
if (!pe || !ascii_strcasematch (pe, ".exe"))
|
|
|
|
pe = strrchr (p, '\0');
|
|
|
|
sys_mbstowcs (pn = progname, NAME_MAX, p, pe - p);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2015-07-20 04:38:30 +08:00
|
|
|
{
|
|
|
|
PWCHAR p = wcsrchr (global_progname, L'\\');
|
|
|
|
++p;
|
|
|
|
PWCHAR pe = wcsrchr (p, '.');
|
|
|
|
if (!pe || wcscasecmp (pe, L".exe"))
|
|
|
|
pe = wcsrchr (p, L'\0');
|
|
|
|
pe = wcpncpy (progname, p, pe - p);
|
|
|
|
*pe = L'\0';
|
|
|
|
pn = progname;
|
|
|
|
}
|
2005-12-30 04:46:34 +08:00
|
|
|
char tmpbuf[20];
|
2015-07-20 04:38:30 +08:00
|
|
|
count = __small_sprintf (buf, fmt, pn, mypid (tmpbuf),
|
2000-10-24 10:25:27 +08:00
|
|
|
execing ? "!" : "");
|
2000-08-03 03:26:01 +08:00
|
|
|
if (func)
|
|
|
|
count += getfunc (buf + count, func);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
count += __small_vsprintf (buf + count, infmt, ap);
|
|
|
|
char *p;
|
|
|
|
for (p = buf + count; p > buf; p--)
|
|
|
|
switch (p[-1])
|
|
|
|
{
|
|
|
|
case '\n':
|
|
|
|
p[-1] = '\0';
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
*--p = '\0';
|
2003-12-08 06:37:12 +08:00
|
|
|
nonewline = true;
|
2000-02-18 03:38:33 +08:00
|
|
|
goto done;
|
|
|
|
default:
|
|
|
|
goto addnl;
|
|
|
|
}
|
|
|
|
|
|
|
|
addnl:
|
|
|
|
*p++ = '\n';
|
|
|
|
*p = '\0';
|
2003-12-08 06:37:12 +08:00
|
|
|
nonewline = false;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
return p - buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write to strace file or strace queue. */
|
2000-03-07 13:33:09 +08:00
|
|
|
void
|
|
|
|
strace::write (unsigned category, const char *buf, int count)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
# define PREFIX (3 + 8 + 1 + 8 + 1)
|
|
|
|
char outbuf[PREFIX + 1 + count + 1];
|
|
|
|
# define outstuff (outbuf + 12)
|
|
|
|
__small_sprintf (outstuff, "%x %s", category, buf);
|
|
|
|
__small_sprintf (outbuf, "cYg%08x", strlen (outstuff) + 1);
|
|
|
|
outstuff[-1] = ' ';
|
|
|
|
OutputDebugString (outbuf);
|
2000-10-24 10:25:27 +08:00
|
|
|
#undef outstuff
|
|
|
|
#undef PREFIX
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2005-12-30 04:46:34 +08:00
|
|
|
void
|
2013-04-23 17:44:36 +08:00
|
|
|
strace::write_childpid (pid_t pid)
|
2005-12-30 04:46:34 +08:00
|
|
|
{
|
|
|
|
char buf[30];
|
|
|
|
|
|
|
|
if (!attached () || !being_debugged ())
|
|
|
|
return;
|
|
|
|
__small_sprintf (buf, "cYg%8x %x", _STRACE_CHILD_PID, pid);
|
|
|
|
OutputDebugString (buf);
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Printf function used when tracing system calls.
|
|
|
|
Warning: DO NOT SET ERRNO HERE! */
|
2015-07-20 04:38:30 +08:00
|
|
|
static NO_COPY muto strace_buf_guard;
|
|
|
|
static NO_COPY char *buf;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
void
|
2001-02-26 17:50:24 +08:00
|
|
|
strace::vprntf (unsigned category, const char *func, const char *fmt, va_list ap)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
DWORD err = GetLastError ();
|
2005-12-27 03:34:59 +08:00
|
|
|
int len;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2015-07-20 04:38:30 +08:00
|
|
|
strace_buf_guard.init ("smallprint_buf")->acquire ();
|
|
|
|
/* Creating buffer on Windows process heap to drop stack pressure and
|
|
|
|
keeping our .bss small. */
|
|
|
|
if (!buf)
|
|
|
|
buf = (char *) HeapAlloc (GetProcessHeap (), 0, NT_MAX_PATH);
|
|
|
|
if (!buf)
|
|
|
|
return;
|
2002-09-22 11:38:57 +08:00
|
|
|
PROTECT (buf);
|
2000-08-02 11:42:31 +08:00
|
|
|
SetLastError (err);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-12-27 03:34:59 +08:00
|
|
|
len = vsprntf (buf, func, fmt, ap);
|
2002-09-22 11:38:57 +08:00
|
|
|
CHECK (buf);
|
2000-08-02 11:42:31 +08:00
|
|
|
if (category & _STRACE_SYSTEM)
|
|
|
|
{
|
|
|
|
DWORD done;
|
2005-12-27 03:34:59 +08:00
|
|
|
WriteFile (GetStdHandle (STD_ERROR_HANDLE), buf, len, &done, 0);
|
2000-08-02 11:42:31 +08:00
|
|
|
FlushFileBuffers (GetStdHandle (STD_ERROR_HANDLE));
|
2005-12-27 03:34:59 +08:00
|
|
|
/* Make sure that the message shows up on the screen, too, since this is
|
|
|
|
a serious error. */
|
|
|
|
if (GetFileType (GetStdHandle (STD_ERROR_HANDLE)) != FILE_TYPE_CHAR)
|
|
|
|
{
|
|
|
|
HANDLE h = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE,
|
2011-07-04 23:25:36 +08:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
2005-12-27 03:34:59 +08:00
|
|
|
&sec_none, OPEN_EXISTING, 0, 0);
|
|
|
|
if (h != INVALID_HANDLE_VALUE)
|
2011-05-03 01:05:10 +08:00
|
|
|
{
|
|
|
|
WriteFile (h, buf, len, &done, 0);
|
|
|
|
CloseHandle (h);
|
|
|
|
}
|
2005-12-27 03:34:59 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-08-02 11:42:31 +08:00
|
|
|
|
|
|
|
#ifndef NOSTRACE
|
2005-12-30 04:46:34 +08:00
|
|
|
if (active ())
|
2005-12-27 03:34:59 +08:00
|
|
|
write (category, buf, len);
|
2000-08-02 11:42:31 +08:00
|
|
|
#endif
|
2015-07-20 04:38:30 +08:00
|
|
|
strace_buf_guard.release ();
|
2000-02-18 03:38:33 +08:00
|
|
|
SetLastError (err);
|
|
|
|
}
|
|
|
|
|
2001-02-26 17:50:24 +08:00
|
|
|
void
|
|
|
|
strace::prntf (unsigned category, const char *func, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
2003-02-04 11:01:17 +08:00
|
|
|
vprntf (category, func, fmt, ap);
|
2009-10-14 12:17:05 +08:00
|
|
|
va_end (ap);
|
2001-02-26 17:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
strace_printf (unsigned category, const char *func, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2005-12-30 04:46:34 +08:00
|
|
|
if ((category & _STRACE_SYSTEM) || strace.active ())
|
2001-02-26 17:50:24 +08:00
|
|
|
{
|
|
|
|
va_start (ap, fmt);
|
|
|
|
strace.vprntf (category, func, fmt, ap);
|
2009-10-14 12:17:05 +08:00
|
|
|
va_end (ap);
|
2001-02-26 17:50:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-13 09:35:15 +08:00
|
|
|
static NO_COPY struct tab
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int v;
|
|
|
|
const char *n;
|
|
|
|
}
|
|
|
|
ta[] =
|
|
|
|
{
|
|
|
|
{ WM_NULL, "WM_NULL" },
|
|
|
|
{ WM_CREATE, "WM_CREATE" },
|
|
|
|
{ WM_DESTROY, "WM_DESTROY" },
|
|
|
|
{ WM_MOVE, "WM_MOVE" },
|
|
|
|
{ WM_SIZE, "WM_SIZE" },
|
|
|
|
{ WM_ACTIVATE, "WM_ACTIVATE" },
|
|
|
|
{ WM_SETFOCUS, "WM_SETFOCUS" },
|
|
|
|
{ WM_KILLFOCUS, "WM_KILLFOCUS" },
|
|
|
|
{ WM_ENABLE, "WM_ENABLE" },
|
|
|
|
{ WM_SETREDRAW, "WM_SETREDRAW" },
|
|
|
|
{ WM_SETTEXT, "WM_SETTEXT" },
|
|
|
|
{ WM_GETTEXT, "WM_GETTEXT" },
|
|
|
|
{ WM_GETTEXTLENGTH, "WM_GETTEXTLENGTH" },
|
|
|
|
{ WM_PAINT, "WM_PAINT" },
|
|
|
|
{ WM_CLOSE, "WM_CLOSE" },
|
|
|
|
{ WM_QUERYENDSESSION, "WM_QUERYENDSESSION" },
|
|
|
|
{ WM_QUIT, "WM_QUIT" },
|
|
|
|
{ WM_QUERYOPEN, "WM_QUERYOPEN" },
|
|
|
|
{ WM_ERASEBKGND, "WM_ERASEBKGND" },
|
|
|
|
{ WM_SYSCOLORCHANGE, "WM_SYSCOLORCHANGE" },
|
|
|
|
{ WM_ENDSESSION, "WM_ENDSESSION" },
|
|
|
|
{ WM_SHOWWINDOW, "WM_SHOWWINDOW" },
|
|
|
|
{ WM_WININICHANGE, "WM_WININICHANGE" },
|
|
|
|
{ WM_DEVMODECHANGE, "WM_DEVMODECHANGE" },
|
|
|
|
{ WM_ACTIVATEAPP, "WM_ACTIVATEAPP" },
|
|
|
|
{ WM_FONTCHANGE, "WM_FONTCHANGE" },
|
|
|
|
{ WM_TIMECHANGE, "WM_TIMECHANGE" },
|
|
|
|
{ WM_CANCELMODE, "WM_CANCELMODE" },
|
|
|
|
{ WM_SETCURSOR, "WM_SETCURSOR" },
|
|
|
|
{ WM_MOUSEACTIVATE, "WM_MOUSEACTIVATE" },
|
|
|
|
{ WM_CHILDACTIVATE, "WM_CHILDACTIVATE" },
|
|
|
|
{ WM_QUEUESYNC, "WM_QUEUESYNC" },
|
|
|
|
{ WM_GETMINMAXINFO, "WM_GETMINMAXINFO" },
|
|
|
|
{ WM_PAINTICON, "WM_PAINTICON" },
|
|
|
|
{ WM_ICONERASEBKGND, "WM_ICONERASEBKGND" },
|
|
|
|
{ WM_NEXTDLGCTL, "WM_NEXTDLGCTL" },
|
|
|
|
{ WM_SPOOLERSTATUS, "WM_SPOOLERSTATUS" },
|
|
|
|
{ WM_DRAWITEM, "WM_DRAWITEM" },
|
|
|
|
{ WM_MEASUREITEM, "WM_MEASUREITEM" },
|
|
|
|
{ WM_DELETEITEM, "WM_DELETEITEM" },
|
|
|
|
{ WM_VKEYTOITEM, "WM_VKEYTOITEM" },
|
|
|
|
{ WM_CHARTOITEM, "WM_CHARTOITEM" },
|
|
|
|
{ WM_SETFONT, "WM_SETFONT" },
|
|
|
|
{ WM_GETFONT, "WM_GETFONT" },
|
|
|
|
{ WM_SETHOTKEY, "WM_SETHOTKEY" },
|
|
|
|
{ WM_GETHOTKEY, "WM_GETHOTKEY" },
|
|
|
|
{ WM_QUERYDRAGICON, "WM_QUERYDRAGICON" },
|
|
|
|
{ WM_COMPAREITEM, "WM_COMPAREITEM" },
|
|
|
|
{ WM_COMPACTING, "WM_COMPACTING" },
|
|
|
|
{ WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING" },
|
|
|
|
{ WM_WINDOWPOSCHANGED, "WM_WINDOWPOSCHANGED" },
|
|
|
|
{ WM_POWER, "WM_POWER" },
|
|
|
|
{ WM_COPYDATA, "WM_COPYDATA" },
|
|
|
|
{ WM_CANCELJOURNAL, "WM_CANCELJOURNAL" },
|
|
|
|
{ WM_NCCREATE, "WM_NCCREATE" },
|
|
|
|
{ WM_NCDESTROY, "WM_NCDESTROY" },
|
|
|
|
{ WM_NCCALCSIZE, "WM_NCCALCSIZE" },
|
|
|
|
{ WM_NCHITTEST, "WM_NCHITTEST" },
|
|
|
|
{ WM_NCPAINT, "WM_NCPAINT" },
|
|
|
|
{ WM_NCACTIVATE, "WM_NCACTIVATE" },
|
|
|
|
{ WM_GETDLGCODE, "WM_GETDLGCODE" },
|
|
|
|
{ WM_NCMOUSEMOVE, "WM_NCMOUSEMOVE" },
|
|
|
|
{ WM_NCLBUTTONDOWN, "WM_NCLBUTTONDOWN" },
|
|
|
|
{ WM_NCLBUTTONUP, "WM_NCLBUTTONUP" },
|
|
|
|
{ WM_NCLBUTTONDBLCLK, "WM_NCLBUTTONDBLCLK" },
|
|
|
|
{ WM_NCRBUTTONDOWN, "WM_NCRBUTTONDOWN" },
|
|
|
|
{ WM_NCRBUTTONUP, "WM_NCRBUTTONUP" },
|
|
|
|
{ WM_NCRBUTTONDBLCLK, "WM_NCRBUTTONDBLCLK" },
|
|
|
|
{ WM_NCMBUTTONDOWN, "WM_NCMBUTTONDOWN" },
|
|
|
|
{ WM_NCMBUTTONUP, "WM_NCMBUTTONUP" },
|
|
|
|
{ WM_NCMBUTTONDBLCLK, "WM_NCMBUTTONDBLCLK" },
|
|
|
|
{ WM_KEYFIRST, "WM_KEYFIRST" },
|
|
|
|
{ WM_KEYDOWN, "WM_KEYDOWN" },
|
|
|
|
{ WM_KEYUP, "WM_KEYUP" },
|
|
|
|
{ WM_CHAR, "WM_CHAR" },
|
|
|
|
{ WM_DEADCHAR, "WM_DEADCHAR" },
|
|
|
|
{ WM_SYSKEYDOWN, "WM_SYSKEYDOWN" },
|
|
|
|
{ WM_SYSKEYUP, "WM_SYSKEYUP" },
|
|
|
|
{ WM_SYSCHAR, "WM_SYSCHAR" },
|
|
|
|
{ WM_SYSDEADCHAR, "WM_SYSDEADCHAR" },
|
|
|
|
{ WM_KEYLAST, "WM_KEYLAST" },
|
|
|
|
{ WM_INITDIALOG, "WM_INITDIALOG" },
|
|
|
|
{ WM_COMMAND, "WM_COMMAND" },
|
|
|
|
{ WM_SYSCOMMAND, "WM_SYSCOMMAND" },
|
|
|
|
{ WM_TIMER, "WM_TIMER" },
|
|
|
|
{ WM_HSCROLL, "WM_HSCROLL" },
|
|
|
|
{ WM_VSCROLL, "WM_VSCROLL" },
|
|
|
|
{ WM_INITMENU, "WM_INITMENU" },
|
|
|
|
{ WM_INITMENUPOPUP, "WM_INITMENUPOPUP" },
|
|
|
|
{ WM_MENUSELECT, "WM_MENUSELECT" },
|
|
|
|
{ WM_MENUCHAR, "WM_MENUCHAR" },
|
|
|
|
{ WM_ENTERIDLE, "WM_ENTERIDLE" },
|
|
|
|
{ WM_CTLCOLORMSGBOX, "WM_CTLCOLORMSGBOX" },
|
|
|
|
{ WM_CTLCOLOREDIT, "WM_CTLCOLOREDIT" },
|
|
|
|
{ WM_CTLCOLORLISTBOX, "WM_CTLCOLORLISTBOX" },
|
|
|
|
{ WM_CTLCOLORBTN, "WM_CTLCOLORBTN" },
|
|
|
|
{ WM_CTLCOLORDLG, "WM_CTLCOLORDLG" },
|
|
|
|
{ WM_CTLCOLORSCROLLBAR, "WM_CTLCOLORSCROLLBAR" },
|
|
|
|
{ WM_CTLCOLORSTATIC, "WM_CTLCOLORSTATIC" },
|
|
|
|
{ WM_MOUSEFIRST, "WM_MOUSEFIRST" },
|
|
|
|
{ WM_MOUSEMOVE, "WM_MOUSEMOVE" },
|
|
|
|
{ WM_LBUTTONDOWN, "WM_LBUTTONDOWN" },
|
|
|
|
{ WM_LBUTTONUP, "WM_LBUTTONUP" },
|
|
|
|
{ WM_LBUTTONDBLCLK, "WM_LBUTTONDBLCLK" },
|
|
|
|
{ WM_RBUTTONDOWN, "WM_RBUTTONDOWN" },
|
|
|
|
{ WM_RBUTTONUP, "WM_RBUTTONUP" },
|
|
|
|
{ WM_RBUTTONDBLCLK, "WM_RBUTTONDBLCLK" },
|
|
|
|
{ WM_MBUTTONDOWN, "WM_MBUTTONDOWN" },
|
|
|
|
{ WM_MBUTTONUP, "WM_MBUTTONUP" },
|
|
|
|
{ WM_MBUTTONDBLCLK, "WM_MBUTTONDBLCLK" },
|
|
|
|
{ WM_MOUSELAST, "WM_MOUSELAST" },
|
|
|
|
{ WM_PARENTNOTIFY, "WM_PARENTNOTIFY" },
|
|
|
|
{ WM_ENTERMENULOOP, "WM_ENTERMENULOOP" },
|
|
|
|
{ WM_EXITMENULOOP, "WM_EXITMENULOOP" },
|
|
|
|
{ WM_MDICREATE, "WM_MDICREATE" },
|
|
|
|
{ WM_MDIDESTROY, "WM_MDIDESTROY" },
|
|
|
|
{ WM_MDIACTIVATE, "WM_MDIACTIVATE" },
|
|
|
|
{ WM_MDIRESTORE, "WM_MDIRESTORE" },
|
|
|
|
{ WM_MDINEXT, "WM_MDINEXT" },
|
|
|
|
{ WM_MDIMAXIMIZE, "WM_MDIMAXIMIZE" },
|
|
|
|
{ WM_MDITILE, "WM_MDITILE" },
|
|
|
|
{ WM_MDICASCADE, "WM_MDICASCADE" },
|
|
|
|
{ WM_MDIICONARRANGE, "WM_MDIICONARRANGE" },
|
|
|
|
{ WM_MDIGETACTIVE, "WM_MDIGETACTIVE" },
|
|
|
|
{ WM_MDISETMENU, "WM_MDISETMENU" },
|
|
|
|
{ WM_DROPFILES, "WM_DROPFILES" },
|
|
|
|
{ WM_MDIREFRESHMENU, "WM_MDIREFRESHMENU" },
|
|
|
|
{ WM_CUT, "WM_CUT" },
|
|
|
|
{ WM_COPY, "WM_COPY" },
|
|
|
|
{ WM_PASTE, "WM_PASTE" },
|
|
|
|
{ WM_CLEAR, "WM_CLEAR" },
|
|
|
|
{ WM_UNDO, "WM_UNDO" },
|
|
|
|
{ WM_RENDERFORMAT, "WM_RENDERFORMAT" },
|
|
|
|
{ WM_RENDERALLFORMATS, "WM_RENDERALLFORMATS" },
|
|
|
|
{ WM_DESTROYCLIPBOARD, "WM_DESTROYCLIPBOARD" },
|
|
|
|
{ WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD" },
|
|
|
|
{ WM_PAINTCLIPBOARD, "WM_PAINTCLIPBOARD" },
|
|
|
|
{ WM_VSCROLLCLIPBOARD, "WM_VSCROLLCLIPBOARD" },
|
|
|
|
{ WM_SIZECLIPBOARD, "WM_SIZECLIPBOARD" },
|
|
|
|
{ WM_ASKCBFORMATNAME, "WM_ASKCBFORMATNAME" },
|
|
|
|
{ WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN" },
|
|
|
|
{ WM_HSCROLLCLIPBOARD, "WM_HSCROLLCLIPBOARD" },
|
|
|
|
{ WM_QUERYNEWPALETTE, "WM_QUERYNEWPALETTE" },
|
|
|
|
{ WM_PALETTEISCHANGING, "WM_PALETTEISCHANGING" },
|
|
|
|
{ WM_PALETTECHANGED, "WM_PALETTECHANGED" },
|
|
|
|
{ WM_HOTKEY, "WM_HOTKEY" },
|
|
|
|
{ WM_PENWINFIRST, "WM_PENWINFIRST" },
|
|
|
|
{ WM_PENWINLAST, "WM_PENWINLAST" },
|
|
|
|
{ WM_ASYNCIO, "ASYNCIO" },
|
|
|
|
{ 0, 0 }};
|
|
|
|
|
2000-03-07 13:33:09 +08:00
|
|
|
void
|
|
|
|
strace::wm (int message, int word, int lon)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-12-30 04:46:34 +08:00
|
|
|
if (active ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; ta[i].n; i++)
|
|
|
|
{
|
|
|
|
if (ta[i].v == message)
|
|
|
|
{
|
2003-02-04 11:01:17 +08:00
|
|
|
prntf (_STRACE_WM, NULL, "wndproc %d %s %d %d", message, ta[i].n, word, lon);
|
2000-02-18 03:38:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-02-04 11:01:17 +08:00
|
|
|
prntf (_STRACE_WM, NULL, "wndproc %d unknown %d %d", message, word, lon);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /*NOSTRACE*/
|