Skip to content

Commit

Permalink
i#2876 clang-format: massive reformat of every file (#3093)
Browse files Browse the repository at this point in the history
Massive clang-format of every C or C++ source file (*.h, *.c, *.cpp),
except for:
+ third_party/
+ ext/drsysm/libelftc/include/
+ ext/drsyms/demangle.cc

This is a single, large commit by design to present a single history
disruption point and bring the code base into a consistent format.
clang-format version 6.0 was used.

Tweaks the clang-format rules to indent 4 after pre-processor hashes, to
allow single-line case labels, and align trailing comments.

Disables the pp_indent vera style check as we changed the indent rule and
clang-format now covers it.  Leaves the other checks, even though some are
redundant (they found clang-format errors).

Moves C++ token defines from globals_shared.h and globals.h to a new
header, core/lib/c_defines.h, to avoid a clang-format parsing error where
it fails to identify the include guard.

Adds genapi.pl removal of extra indentation inside API_EXPORT_ONLY and
CLIENT_INTERFACE regions.

Adds exclusions around large regions we don't want to format, in these
files:
+ core/win32/syscallx.h
+ core/arch/x86/decode_table.c
+ core/arch/arm/table_a32_pred.c
+ core/arch/arm/table_a32_unpred.c
+ core/arch/arm/table_t32_16.c
+ core/arch/arm/table_t32_16_it.c
+ core/arch/arm/table_t32_base.c
+ core/arch/arm/table_t32_coproc.c
+ core/arch/arm/table_encode.c

Adds smaller exclusions to work around clang-format bugs:
+ Several missing break-after-return-type
+ Several >90-char lines
+ Misc scattered issues, all listed in #2876

Issue: #2876
  • Loading branch information
derekbruening authored Jul 8, 2018
1 parent d9f2175 commit f1713ec
Show file tree
Hide file tree
Showing 864 changed files with 87,660 additions and 91,939 deletions.
4 changes: 3 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
BasedOnStyle: WebKit
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: All
Expand All @@ -12,7 +14,7 @@ BinPackParameters: true
BreakBeforeBinaryOperators: None
ColumnLimit: 90
IndentWidth: 4
IndentPPDirectives: None # AfterHash uses global IndentWidth....
IndentPPDirectives: AfterHash
PointerAlignment: Right
CommentPragmas: '^ clang-format: '
SortIncludes: false
Expand Down
137 changes: 67 additions & 70 deletions api/samples/MF_moduledb.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,31 @@
#define NAME "MF_moduledb"

#ifdef SHOW_RESULTS
# if defined(WINDOWS) && USE_MESSAGEBOX
# define DISPLAY_FUNC dr_messagebox
# else /* no messageboxes, use dr_printf() instead */
# define DISPLAY_FUNC dr_printf
# endif
# if defined(WINDOWS) && USE_MESSAGEBOX
# define DISPLAY_FUNC dr_messagebox
# else /* no messageboxes, use dr_printf() instead */
# define DISPLAY_FUNC dr_printf
# endif
#else
# define DISPLAY_FUNC dummy_func
# define DISPLAY_FUNC dummy_func
#endif

#if VERBOSE
# define VDISPLAY_FUNC DISPLAY_FUNC
# define VDISPLAY_FUNC DISPLAY_FUNC
#else
# define VDISPLAY_FUNC dummy_func
# define VDISPLAY_FUNC dummy_func
#endif
#if VVERBOSE
# define VVDISPLAY_FUNC DISPLAY_FUNC
# define VVDISPLAY_FUNC DISPLAY_FUNC
#else
# define VVDISPLAY_FUNC dummy_func
# define VVDISPLAY_FUNC dummy_func
#endif

/* used to avoid displaying a string */
static void dummy_func(char *fmt, ...) {}
static void
dummy_func(char *fmt, ...)
{
}

typedef struct {
char module_name[MAXIMUM_PATH];
Expand All @@ -122,32 +125,36 @@ typedef struct _table_entry_t table_entry_t;
struct _table_entry_t {
table_value_t value; /* the entry we read out of the config file */
table_entry_t *next; /* table is just a singly linked list */
}; /* table_entry_t */
}; /* table_entry_t */

static const char *table_def_file_name; /* name of configuration file */
static void *table_lock; /* for multithreaded access to the table */
static table_entry_t *table = NULL; /* table of relaxations */

static void event_security_violation(void *drcontext, void *source_tag,
app_pc source_pc, app_pc target_pc,
dr_security_violation_type_t violation,
dr_mcontext_t *mcontext,
dr_security_violation_action_t *action);
static void event_nudge(void *drcontext, uint64 argument);
static void event_about_to_terminate_nudges(int total_non_app_threads,
int live_non_app_threads);
static void event_exit(void);

static table_entry_t * get_entry_for_address(app_pc addr);
static void read_table();
static void free_table();
static void *table_lock; /* for multithreaded access to the table */
static table_entry_t *table = NULL; /* table of relaxations */

static void
event_security_violation(void *drcontext, void *source_tag, app_pc source_pc,
app_pc target_pc, dr_security_violation_type_t violation,
dr_mcontext_t *mcontext, dr_security_violation_action_t *action);
static void
event_nudge(void *drcontext, uint64 argument);
static void
event_about_to_terminate_nudges(int total_non_app_threads, int live_non_app_threads);
static void
event_exit(void);

static table_entry_t *
get_entry_for_address(app_pc addr);
static void
read_table();
static void
free_table();

DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
dr_set_client_name("DynamoRIO Sample Client 'MF_moduledb'",
"http://dynamorio.org/issues");
VDISPLAY_FUNC(NAME" initializing.");
VDISPLAY_FUNC(NAME " initializing.");

/* register the events we wish to handle */
dr_register_security_event(event_security_violation);
Expand All @@ -156,9 +163,8 @@ dr_client_main(client_id_t id, int argc, const char *argv[])

/* read the client options */
table_def_file_name = dr_get_options(id);
if (table_def_file_name == NULL ||
table_def_file_name[0] == '\0') {
DISPLAY_FUNC(NAME" requires the table name as parameter\n");
if (table_def_file_name == NULL || table_def_file_name[0] == '\0') {
DISPLAY_FUNC(NAME " requires the table name as parameter\n");
dr_abort();
}

Expand All @@ -170,7 +176,7 @@ dr_client_main(client_id_t id, int argc, const char *argv[])
static void
event_exit(void)
{
VDISPLAY_FUNC(NAME" exiting.");
VDISPLAY_FUNC(NAME " exiting.");

/* free structures */
free_table();
Expand All @@ -180,7 +186,7 @@ event_exit(void)
static void
event_nudge(void *drcontext, uint64 argument)
{
DISPLAY_FUNC(NAME" received nudge event; re-reading config file.");
DISPLAY_FUNC(NAME " received nudge event; re-reading config file.");

/* An external process has nudged us with dr_nudge_process() telling us
* to re-read the configuration file. */
Expand Down Expand Up @@ -210,15 +216,13 @@ get_entry_for_address(app_pc addr)
#endif

static void
event_security_violation(void *drcontext, void *source_tag,
app_pc source_pc, app_pc target_pc,
dr_security_violation_type_t violation,
dr_mcontext_t *mcontext,
dr_security_violation_action_t *action)
event_security_violation(void *drcontext, void *source_tag, app_pc source_pc,
app_pc target_pc, dr_security_violation_type_t violation,
dr_mcontext_t *mcontext, dr_security_violation_action_t *action)
{
/* A potential security violation was detected. */
char *violation_str = NULL; /* a name for this violation */
bool allow = false; /* should we let execution continue */
bool allow = false; /* should we let execution continue */

#ifdef WINDOWS
/* find the module we came from */
Expand Down Expand Up @@ -254,24 +258,12 @@ event_security_violation(void *drcontext, void *source_tag,
#endif

switch (violation) {
case DR_RCO_STACK_VIOLATION:
violation_str = "stack execution violation";
break;
case DR_RCO_HEAP_VIOLATION:
violation_str = "heap execution violation";
break;
case DR_RCT_RETURN_VIOLATION:
violation_str = "return target violation";
break;
case DR_RCT_INDIRECT_CALL_VIOLATION:
violation_str = "call transfer violation";
break;
case DR_RCT_INDIRECT_JUMP_VIOLATION:
violation_str = "jump transfer violation";
break;
default:
violation_str = "unknown";
break;
case DR_RCO_STACK_VIOLATION: violation_str = "stack execution violation"; break;
case DR_RCO_HEAP_VIOLATION: violation_str = "heap execution violation"; break;
case DR_RCT_RETURN_VIOLATION: violation_str = "return target violation"; break;
case DR_RCT_INDIRECT_CALL_VIOLATION: violation_str = "call transfer violation"; break;
case DR_RCT_INDIRECT_JUMP_VIOLATION: violation_str = "jump transfer violation"; break;
default: violation_str = "unknown"; break;
}

if (allow)
Expand All @@ -291,11 +283,11 @@ read_table()

file = dr_open_file(table_def_file_name, DR_FILE_READ);
if (file == INVALID_FILE) {
DISPLAY_FUNC(NAME" error opening config file \"%s\"\n", table_def_file_name);
DISPLAY_FUNC(NAME " error opening config file \"%s\"\n", table_def_file_name);
return;
}

VVDISPLAY_FUNC(NAME" reading config file: \"%s\"\n", table_def_file_name);
VVDISPLAY_FUNC(NAME " reading config file: \"%s\"\n", table_def_file_name);

do {
table_entry_t *entry = (table_entry_t *)dr_global_alloc(sizeof(table_entry_t));
Expand All @@ -312,22 +304,27 @@ read_table()
entry->value.module_name[i] = '\0';
}
/* just in case */
entry->value.module_name[sizeof(entry->value.module_name)-1] = '\0';
entry->value.module_name[sizeof(entry->value.module_name) - 1] = '\0';

/* add to the table */
entry->next = table;
table = entry;
VVDISPLAY_FUNC(NAME" read entry for module=\"%s\" to_stack=%s to_heap=%s "
"transfer_to_here=%s\n", entry->value.module_name,
(entry->value.allow_to_stack == 'y' ||
entry->value.allow_to_stack == 'Y') ? "yes" : "no",
(entry->value.allow_to_heap == 'y' ||
entry->value.allow_to_heap == 'Y') ? "yes" : "no",
(entry->value.allow_to_here == 'y' ||
entry->value.allow_to_here == 'Y') ? "yes" : "no");
VVDISPLAY_FUNC(
NAME " read entry for module=\"%s\" to_stack=%s to_heap=%s "
"transfer_to_here=%s\n",
entry->value.module_name,
(entry->value.allow_to_stack == 'y' || entry->value.allow_to_stack == 'Y')
? "yes"
: "no",
(entry->value.allow_to_heap == 'y' || entry->value.allow_to_heap == 'Y')
? "yes"
: "no",
(entry->value.allow_to_here == 'y' || entry->value.allow_to_here == 'Y')
? "yes"
: "no");
}
} while (read_entry);
VVDISPLAY_FUNC(NAME" done reading config file.");
VVDISPLAY_FUNC(NAME " done reading config file.");
}

static void
Expand Down
13 changes: 5 additions & 8 deletions api/samples/bbbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst
drx_buf_insert_load_buf_ptr(drcontext, buf, bb, inst, reg);

/* store bb's start pc into the buffer */
drx_buf_insert_buf_store(drcontext, buf, bb, inst, reg, reg2,
OPND_CREATE_INTPTR(pc), OPSZ_PTR, 0);
drx_buf_insert_buf_store(drcontext, buf, bb, inst, reg, reg2, OPND_CREATE_INTPTR(pc),
OPSZ_PTR, 0);

/* Internally this will update the TLS buffer pointer by incrementing just the bottom
* 16 bits of the pointer.
Expand Down Expand Up @@ -142,11 +142,9 @@ event_exit(void)
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
drreg_options_t ops = {sizeof(ops), 2 /*max slots needed*/, false};
dr_set_client_name("DynamoRIO Sample Client 'bbbuf'",
"http://dynamorio.org/issues");
if (!drmgr_init() || !drx_init() ||
drreg_init(&ops) != DRREG_SUCCESS)
drreg_options_t ops = { sizeof(ops), 2 /*max slots needed*/, false };
dr_set_client_name("DynamoRIO Sample Client 'bbbuf'", "http://dynamorio.org/issues");
if (!drmgr_init() || !drx_init() || drreg_init(&ops) != DRREG_SUCCESS)
DR_ASSERT(false);

buf = drx_buf_create_circular_buffer(DRX_BUF_FAST_CIRCULAR_BUFSZ);
Expand All @@ -158,4 +156,3 @@ dr_client_main(client_id_t id, int argc, const char *argv[])
!drmgr_register_bb_instrumentation_event(NULL, event_app_instruction, NULL))
DR_ASSERT(false);
}

26 changes: 13 additions & 13 deletions api/samples/bbcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
#include "drx.h"

#ifdef WINDOWS
# define DISPLAY_STRING(msg) dr_messagebox(msg)
# define DISPLAY_STRING(msg) dr_messagebox(msg)
#else
# define DISPLAY_STRING(msg) dr_printf("%s\n", msg);
# define DISPLAY_STRING(msg) dr_printf("%s\n", msg);
#endif

#define NULL_TERMINATE(buf) buf[(sizeof(buf)/sizeof(buf[0])) - 1] = '\0'
#define NULL_TERMINATE(buf) buf[(sizeof(buf) / sizeof(buf[0])) - 1] = '\0'

#define TESTALL(mask, var) (((mask) & (var)) == (mask))
#define TESTANY(mask, var) (((mask) & (var)) != 0)
Expand All @@ -71,7 +71,7 @@ event_exit(void)
#ifdef SHOW_RESULTS
char msg[512];
int len;
len = dr_snprintf(msg, sizeof(msg)/sizeof(msg[0]),
len = dr_snprintf(msg, sizeof(msg) / sizeof(msg[0]),
"Instrumentation results:\n"
"%10d basic block executions\n"
"%10d basic blocks needed flag saving\n"
Expand Down Expand Up @@ -104,10 +104,10 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst
return DR_EMIT_DEFAULT;

#ifdef VERBOSE
dr_printf("in dynamorio_basic_block(tag="PFX")\n", tag);
# ifdef VERBOSE_VERBOSE
dr_printf("in dynamorio_basic_block(tag=" PFX ")\n", tag);
# ifdef VERBOSE_VERBOSE
instrlist_disassemble(drcontext, tag, bb, STDOUT);
# endif
# endif
#endif

#ifdef SHOW_RESULTS
Expand All @@ -123,11 +123,11 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst
/* We're using drmgr, so these slots
* here won't be used: drreg's slots will be.
*/
SPILL_SLOT_MAX+1, IF_AARCHXX_(SPILL_SLOT_MAX+1)
&global_count, 1, 0);
SPILL_SLOT_MAX + 1,
IF_AARCHXX_(SPILL_SLOT_MAX + 1) & global_count, 1, 0);

#if defined(VERBOSE) && defined(VERBOSE_VERBOSE)
dr_printf("Finished instrumenting dynamorio_basic_block(tag="PFX")\n", tag);
dr_printf("Finished instrumenting dynamorio_basic_block(tag=" PFX ")\n", tag);
instrlist_disassemble(drcontext, tag, bb, STDOUT);
#endif
return DR_EMIT_DEFAULT;
Expand All @@ -136,7 +136,7 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
drreg_options_t ops = {sizeof(ops), 1 /*max slots needed: aflags*/, false};
drreg_options_t ops = { sizeof(ops), 1 /*max slots needed: aflags*/, false };
dr_set_client_name("DynamoRIO Sample Client 'bbcount'",
"http://dynamorio.org/issues");
if (!drmgr_init() || !drx_init() || drreg_init(&ops) != DRREG_SUCCESS)
Expand All @@ -152,10 +152,10 @@ dr_client_main(client_id_t id, int argc, const char *argv[])
#ifdef SHOW_RESULTS
/* also give notification to stderr */
if (dr_is_notify_on()) {
# ifdef WINDOWS
# ifdef WINDOWS
/* ask for best-effort printing to cmd window. must be called at init. */
dr_enable_console_printing();
# endif
# endif
dr_fprintf(STDERR, "Client bbcount is running\n");
}
#endif
Expand Down
Loading

0 comments on commit f1713ec

Please sign in to comment.