|
Packit |
ae9e2a |
/*
|
|
Packit |
ae9e2a |
* Copyright (C) the libgit2 contributors. All rights reserved.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
Packit |
ae9e2a |
* a Linking Exception. For full terms see the included COPYING file.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
#ifndef INCLUDE_w32_stack_h__
|
|
Packit |
ae9e2a |
#define INCLUDE_w32_stack_h__
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
#if defined(GIT_MSVC_CRTDBG)
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* This type defines a callback to be used to augment a C stacktrace
|
|
Packit |
ae9e2a |
* with "aux" data. This can be used, for example, to allow LibGit2Sharp
|
|
Packit |
ae9e2a |
* (or other interpreted consumer libraries) to give us C# stacktrace
|
|
Packit |
ae9e2a |
* data for the PInvoke.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This callback will be called during crtdbg-instrumented allocs.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param aux_id [out] A returned "aux_id" representing a unique
|
|
Packit |
ae9e2a |
* (de-duped at the C# layer) stacktrace. "aux_id" 0 is reserved
|
|
Packit |
ae9e2a |
* to mean no aux stacktrace data.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
typedef void (*git_win32__stack__aux_cb_alloc)(unsigned int *aux_id);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* This type defines a callback to be used to augment the output of
|
|
Packit |
ae9e2a |
* a stacktrace. This will be used to request the C# layer format
|
|
Packit |
ae9e2a |
* the C# stacktrace associated with "aux_id" into the provided
|
|
Packit |
ae9e2a |
* buffer.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This callback will be called during leak reporting.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param aux_id The "aux_id" key associated with a stacktrace.
|
|
Packit |
ae9e2a |
* @param aux_msg A buffer where a formatted message should be written.
|
|
Packit |
ae9e2a |
* @param aux_msg_len The size of the buffer.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
typedef void (*git_win32__stack__aux_cb_lookup)(unsigned int aux_id, char *aux_msg, unsigned int aux_msg_len);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Register an "aux" data provider to augment our C stacktrace data.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* This can be used, for example, to allow LibGit2Sharp (or other
|
|
Packit |
ae9e2a |
* interpreted consumer libraries) to give us the C# stacktrace of
|
|
Packit |
ae9e2a |
* the PInvoke.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* If you choose to use this feature, it should be registered during
|
|
Packit |
ae9e2a |
* initialization and not changed for the duration of the process.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
GIT_EXTERN(int) git_win32__stack__set_aux_cb(
|
|
Packit |
ae9e2a |
git_win32__stack__aux_cb_alloc cb_alloc,
|
|
Packit |
ae9e2a |
git_win32__stack__aux_cb_lookup cb_lookup);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Maximum number of stackframes to record for a
|
|
Packit |
ae9e2a |
* single stacktrace.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
#define GIT_WIN32__STACK__MAX_FRAMES 30
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Wrapper containing the raw unprocessed stackframe
|
|
Packit |
ae9e2a |
* data for a single stacktrace and any "aux_id".
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* I put the aux_id first so leaks will be sorted by it.
|
|
Packit |
ae9e2a |
* So, for example, if a specific callstack in C# leaks
|
|
Packit |
ae9e2a |
* a repo handle, all of the pointers within the associated
|
|
Packit |
ae9e2a |
* repo pointer will be grouped together.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
typedef struct {
|
|
Packit |
ae9e2a |
unsigned int aux_id;
|
|
Packit |
ae9e2a |
unsigned int nr_frames;
|
|
Packit |
ae9e2a |
void *frames[GIT_WIN32__STACK__MAX_FRAMES];
|
|
Packit |
ae9e2a |
} git_win32__stack__raw_data;
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Load symbol table data. This should be done in the primary
|
|
Packit |
ae9e2a |
* thread at startup (under a lock if there are other threads
|
|
Packit |
ae9e2a |
* active).
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
void git_win32__stack_init(void);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Cleanup symbol table data. This should be done in the
|
|
Packit |
ae9e2a |
* primary thead at shutdown (under a lock if there are other
|
|
Packit |
ae9e2a |
* threads active).
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
void git_win32__stack_cleanup(void);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Capture raw stack trace data for the current process/thread.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param skip Number of initial frames to skip. Pass 0 to
|
|
Packit |
ae9e2a |
* begin with the caller of this routine. Pass 1 to begin
|
|
Packit |
ae9e2a |
* with its caller. And so on.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
int git_win32__stack_capture(git_win32__stack__raw_data *pdata, int skip);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Compare 2 raw stacktraces with the usual -1,0,+1 result.
|
|
Packit |
ae9e2a |
* This includes any "aux_id" values in the comparison, so that
|
|
Packit |
ae9e2a |
* our de-dup is also "aux" context relative.
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
int git_win32__stack_compare(
|
|
Packit |
ae9e2a |
git_win32__stack__raw_data *d1,
|
|
Packit |
ae9e2a |
git_win32__stack__raw_data *d2);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Format raw stacktrace data into buffer WITHOUT using any mallocs.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param prefix String written before each frame; defaults to "\t".
|
|
Packit |
ae9e2a |
* @param suffix String written after each frame; defaults to "\n".
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
int git_win32__stack_format(
|
|
Packit |
ae9e2a |
char *pbuf, int buf_len,
|
|
Packit |
ae9e2a |
const git_win32__stack__raw_data *pdata,
|
|
Packit |
ae9e2a |
const char *prefix, const char *suffix);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
/**
|
|
Packit |
ae9e2a |
* Convenience routine to capture and format stacktrace into
|
|
Packit |
ae9e2a |
* a buffer WITHOUT using any mallocs. This is primarily a
|
|
Packit |
ae9e2a |
* wrapper for testing.
|
|
Packit |
ae9e2a |
*
|
|
Packit |
ae9e2a |
* @param skip Number of initial frames to skip. Pass 0 to
|
|
Packit |
ae9e2a |
* begin with the caller of this routine. Pass 1 to begin
|
|
Packit |
ae9e2a |
* with its caller. And so on.
|
|
Packit |
ae9e2a |
* @param prefix String written before each frame; defaults to "\t".
|
|
Packit |
ae9e2a |
* @param suffix String written after each frame; defaults to "\n".
|
|
Packit |
ae9e2a |
*/
|
|
Packit |
ae9e2a |
int git_win32__stack(
|
|
Packit |
ae9e2a |
char * pbuf, int buf_len,
|
|
Packit |
ae9e2a |
int skip,
|
|
Packit |
ae9e2a |
const char *prefix, const char *suffix);
|
|
Packit |
ae9e2a |
|
|
Packit |
ae9e2a |
#endif /* GIT_MSVC_CRTDBG */
|
|
Packit |
ae9e2a |
#endif /* INCLUDE_w32_stack_h__ */
|