Skip to content

Commit e9e9d79

Browse files
authored
Update gotcha (#543)
1 parent 0206a20 commit e9e9d79

21 files changed

+1908
-1810
lines changed

ext/gotcha/include/gotcha/gotcha.h

+25-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the terms and conditions of the GNU Lesser General Public License
1111
for more details. You should have received a copy of the GNU Lesser General
1212
Public License along with this program; if not, write to the Free Software
13-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1414
*/
1515

1616
/*!
@@ -22,18 +22,19 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2222
*
2323
* The intended use pattern is as follows
2424
*
25-
* TODO ON-INTERFACE-SOLID: document the interface
26-
* usage
25+
* TODO ON-INTERFACE-SOLID: document the
26+
*interface usage
2727
*
2828
******************************************************************************
2929
*/
3030
#ifndef GOTCHA_H
3131
#define GOTCHA_H
3232

33-
#include "gotcha/gotcha_types.h"
3433
#include <link.h>
3534

36-
#if defined(__cplusplus)
35+
#include "gotcha/gotcha_types.h"
36+
37+
#if defined(__cplusplus)
3738
extern "C" {
3839
#endif
3940

@@ -45,19 +46,20 @@ extern "C" {
4546
* \param name The name of the function you want to get a pointer to
4647
* \param ret_type The return type of the function you want a pointer to
4748
* \param ... A comma separated list of the types of the parameters
48-
* to the function you're getting a pointer to
49+
* to the function you're getting a pointer to
4950
******************************************************************************
5051
*/
5152

52-
#define GOTCHA_MAKE_FUNCTION_PTR(name, ret_type, ...) ret_type(*name)(__VA_ARGS__)
53+
#define GOTCHA_MAKE_FUNCTION_PTR(name, ret_type, ...) \
54+
ret_type (*name)(__VA_ARGS__)
5355

5456
#define GOTCHA_EXPORT __attribute__((__visibility__("default")))
5557

5658
/*!
5759
******************************************************************************
5860
*
59-
* \fn enum gotcha_error_t gotcha_wrap(struct gotcha_binding_t* bindings,
60-
* void** wrappers, void*** originals,
61+
* \fn enum gotcha_error_t gotcha_wrap(struct gotcha_binding_t* bindings,
62+
* void** wrappers, void*** originals,
6163
* int num_actions);
6264
*
6365
* \brief Makes GOTCHA wrap the functions picked in gotcha_prepare_symbols
@@ -70,8 +72,9 @@ extern "C" {
7072
******************************************************************************
7173
*/
7274

73-
GOTCHA_EXPORT enum gotcha_error_t gotcha_wrap(struct gotcha_binding_t* bindings, int num_actions, const char* tool_name);
74-
75+
GOTCHA_EXPORT enum gotcha_error_t gotcha_wrap(struct gotcha_binding_t *bindings,
76+
int num_actions,
77+
const char *tool_name);
7578

7679
/*!
7780
******************************************************************************
@@ -88,7 +91,8 @@ GOTCHA_EXPORT enum gotcha_error_t gotcha_wrap(struct gotcha_binding_t* bindings,
8891
*
8992
******************************************************************************
9093
*/
91-
GOTCHA_EXPORT enum gotcha_error_t gotcha_set_priority(const char* tool_name, int priority);
94+
GOTCHA_EXPORT enum gotcha_error_t gotcha_set_priority(const char *tool_name,
95+
int priority);
9296

9397
/*!
9498
******************************************************************************
@@ -104,28 +108,30 @@ GOTCHA_EXPORT enum gotcha_error_t gotcha_set_priority(const char* tool_name, int
104108
*
105109
******************************************************************************
106110
*/
107-
GOTCHA_EXPORT enum gotcha_error_t gotcha_get_priority(const char* tool_name, int *priority);
111+
GOTCHA_EXPORT enum gotcha_error_t gotcha_get_priority(const char *tool_name,
112+
int *priority);
108113

109114
/*!
110115
******************************************************************************
111116
*
112117
* \fn enum void* gotcha_get_wrappee(gotcha_wrappee_handle_t)
113118
*
114-
* \brief Given a GOTCHA wrapper's handle, returns the wrapped function for it to call
119+
* \brief Given a GOTCHA wrapper's handle, returns the wrapped function for it
120+
*to call
115121
*
116122
* \param handle The wrappee handle to return the function pointer for
117123
*
118124
******************************************************************************
119125
*/
120-
GOTCHA_EXPORT void* gotcha_get_wrappee(gotcha_wrappee_handle_t handle);
126+
GOTCHA_EXPORT void *gotcha_get_wrappee(gotcha_wrappee_handle_t handle);
121127

122-
GOTCHA_EXPORT void gotcha_filter_libraries_by_name(const char* nameFilter);
128+
GOTCHA_EXPORT void gotcha_filter_libraries_by_name(const char *nameFilter);
123129
GOTCHA_EXPORT void gotcha_only_filter_last();
124-
GOTCHA_EXPORT void gotcha_set_library_filter_func(int(*new_func)(struct link_map*));
130+
GOTCHA_EXPORT void gotcha_set_library_filter_func(
131+
int (*new_func)(struct link_map *));
125132
GOTCHA_EXPORT void gotcha_restore_library_filter_func();
126133

127-
128-
#if defined(__cplusplus)
134+
#if defined(__cplusplus)
129135
}
130136
#endif
131137

ext/gotcha/include/gotcha/gotcha_types.h

+15-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the terms and conditions of the GNU Lesser General Public License
1111
for more details. You should have received a copy of the GNU Lesser General
1212
Public License along with this program; if not, write to the Free Software
13-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1414
*/
1515
/*!
1616
******************************************************************************
@@ -24,33 +24,35 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2424
#ifndef GOTCHA_TYPES_H
2525
#define GOTCHA_TYPES_H
2626

27-
#if defined(__cplusplus)
27+
#if defined(__cplusplus)
2828
extern "C" {
2929
#endif
3030

31-
typedef void* gotcha_wrappee_handle_t;
31+
typedef void *gotcha_wrappee_handle_t;
3232

3333
/*!
3434
* The representation of a Gotcha action
3535
* as it passes through the pipeline
3636
*/
3737
typedef struct gotcha_binding_t {
38-
const char* name; //!< The name of the function being wrapped
39-
void* wrapper_pointer; //!< A pointer to the wrapper function
40-
gotcha_wrappee_handle_t* function_handle; //!< A pointer to the function being wrapped
41-
}gotcha_binding_t;
38+
const char *name; //!< The name of the function being wrapped
39+
void *wrapper_pointer; //!< A pointer to the wrapper function
40+
gotcha_wrappee_handle_t
41+
*function_handle; //!< A pointer to the function being wrapped
42+
} gotcha_binding_t;
4243

4344
/*!
4445
* The representation of an error (or success) of a Gotcha action
4546
*/
4647
typedef enum gotcha_error_t {
47-
GOTCHA_SUCCESS = 0, //!< The call succeeded
48-
GOTCHA_FUNCTION_NOT_FOUND, //!< The call looked up a function which could not be found
49-
GOTCHA_INTERNAL, //!< Internal gotcha error
50-
GOTCHA_INVALID_TOOL //!< Invalid tool name
51-
}gotcha_error_t;
48+
GOTCHA_SUCCESS = 0, //!< The call succeeded
49+
GOTCHA_FUNCTION_NOT_FOUND, //!< The call looked up a function which could not
50+
//!< be found
51+
GOTCHA_INTERNAL, //!< Internal gotcha error
52+
GOTCHA_INVALID_TOOL //!< Invalid tool name
53+
} gotcha_error_t;
5254

53-
#if defined(__cplusplus)
55+
#if defined(__cplusplus)
5456
}
5557
#endif
5658

ext/gotcha/src/elf_ops.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the terms and conditions of the GNU Lesser General Public License
1111
for more details. You should have received a copy of the GNU Lesser General
1212
Public License along with this program; if not, write to the Free Software
13-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1414
*/
1515

1616
#include "elf_ops.h"
17-
#include "libc_wrappers.h"
17+
1818
#include <elf.h>
19+
20+
#include "libc_wrappers.h"
1921
struct gnu_hash_header {
20-
uint32_t nbuckets; //!< The number of buckets to hash symbols into
21-
uint32_t symndx; //!< Index of the first symbol accessible via hashtable in the symbol table
22-
uint32_t maskwords; //!< Number of words in the hash table's bloom filter
23-
uint32_t shift2; //!< The bloom filter's shift count
22+
uint32_t nbuckets; //!< The number of buckets to hash symbols into
23+
uint32_t symndx; //!< Index of the first symbol accessible via hashtable in
24+
//!< the symbol table
25+
uint32_t maskwords; //!< Number of words in the hash table's bloom filter
26+
uint32_t shift2; //!< The bloom filter's shift count
2427
};
2528

2629
static uint32_t gnu_hash_func(const char *str) {
@@ -43,15 +46,14 @@ static uint32_t gnu_hash_func(const char *str) {
4346
*/
4447

4548
signed long lookup_gnu_hash_symbol(const char *name, ElfW(Sym) * syms,
46-
ElfW(Half) *versym,
47-
char *symnames,
49+
ElfW(Half) * versym, char *symnames,
4850
void *sheader) {
4951
uint32_t *buckets, *vals;
5052
uint32_t hash_val;
5153
uint32_t cur_sym, cur_sym_hashval;
5254
signed long latest_sym = -1;
5355
ElfW(Half) latest_sym_ver = 0;
54-
struct gnu_hash_header *header = (struct gnu_hash_header *) (sheader);
56+
struct gnu_hash_header *header = (struct gnu_hash_header *)(sheader);
5557

5658
buckets = (uint32_t *)(((unsigned char *)(header + 1)) +
5759
(header->maskwords * sizeof(ElfW(Addr))));
@@ -99,8 +101,8 @@ static unsigned long elf_hash(const unsigned char *name) {
99101
}
100102

101103
signed long lookup_elf_hash_symbol(const char *name, ElfW(Sym) * syms,
102-
ElfW(Half) *versym,
103-
char *symnames, ElfW(Word) * header) {
104+
ElfW(Half) * versym, char *symnames,
105+
ElfW(Word) * header) {
104106
ElfW(Word) *nbucket = header + 0;
105107
ElfW(Word) *buckets = header + 2;
106108
ElfW(Word) *chains = buckets + *nbucket;
@@ -112,7 +114,8 @@ signed long lookup_elf_hash_symbol(const char *name, ElfW(Sym) * syms,
112114
while (y != STN_UNDEF) {
113115
if (gotcha_strcmp(name, symnames + syms[y].st_name) == 0) {
114116
if (!versym) {
115-
return y;
117+
// in general all libs would have version but it is a guard condition.
118+
return y; // GCOVR_EXCL_LINE
116119
}
117120

118121
if ((versym[y] & 0x7fff) > latest_sym_ver) {

0 commit comments

Comments
 (0)