add bitset operations and tests
[hiphop-php.git] / hphp / runtime / vm / debug / gdb-jit.cpp
blob946e693462e826eb0e6f7c7c9819a48dd035a0b2
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #include "hphp/runtime/vm/debug/gdb-jit.h"
17 #include "hphp/util/lock.h"
18 #include "hphp/runtime/base/execution-context.h"
20 #include <stdio.h>
21 #include <stdlib.h>
23 #include <folly/portability/SysMman.h>
25 using namespace HPHP;
27 struct jit_descriptor __jit_debug_descriptor = { 1, 0, 0, 0 };
29 void unregister_gdb_hook(struct jit_code_entry *e) {
30 __jit_debug_descriptor.action_flag = JIT_UNREGISTER_FN;
31 __jit_debug_descriptor.relevant_entry = e;
32 __jit_debug_register_code();
35 void delete_symfile(const char *old) {
36 struct jit_code_entry *e, *prev;
38 e = __jit_debug_descriptor.first_entry;
39 prev = nullptr;
40 while (e != nullptr) {
41 if (e->symfile_addr == old) {
42 if (prev != nullptr) {
43 prev->next_entry = e->next_entry;
44 } else {
45 __jit_debug_descriptor.first_entry = e->next_entry;
47 if (e->next_entry != nullptr) {
48 e->next_entry->prev_entry = prev;
50 unregister_gdb_hook(e);
51 free((void *)e->symfile_addr);
52 free(e);
53 return;
55 prev = e;
56 e = e->next_entry;
60 Mutex gdbLock;
62 void unregister_gdb_chunk(DwarfChunk* d) {
63 Lock lock(gdbLock);
65 if (d->m_symfile != nullptr) {
66 delete_symfile(d->m_symfile);
67 d->m_symfile = nullptr;
71 int register_gdb_hook(char *symfile_addr, uint64_t symfile_size,
72 DwarfChunk* d) {
73 struct jit_code_entry *entry;
74 Lock lock(gdbLock);
76 if ((entry =
77 (struct jit_code_entry *)malloc(sizeof (struct jit_code_entry))) == nullptr)
78 return -1;
80 entry->symfile_addr = symfile_addr;
81 entry->symfile_size = symfile_size;
83 if (d->m_symfile != nullptr) {
84 delete_symfile(d->m_symfile);
86 d->m_symfile = symfile_addr;
88 entry->prev_entry = nullptr;
89 entry->next_entry = __jit_debug_descriptor.first_entry;
90 if (__jit_debug_descriptor.first_entry) {
91 __jit_debug_descriptor.first_entry->prev_entry = entry;
93 __jit_debug_descriptor.first_entry = entry;
94 __jit_debug_descriptor.relevant_entry = entry;
96 __jit_debug_descriptor.action_flag = JIT_REGISTER_FN;
97 __jit_debug_register_code();
98 return 0;