forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.py
145 lines (100 loc) · 3.51 KB
/
repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
Wow okay, let's frob repos from inside gdb.
"""
from compatibility import *
import gdb
import sqlite3
from gdbutils import *
#------------------------------------------------------------------------------
_paths = [ None, None ]
_conns = [ None, None ]
def get(repo_id):
global _conns
try:
return _conns[int(repo_id)]
except:
return None
def set(repo_id, path):
global _paths, _conns
repo_id = int(repo_id)
if repo_id > 1:
return
if _conns[repo_id] is not None:
_conns[repo_id].close()
_paths[repo_id] = path
_conns[repo_id] = sqlite3.connect(path)
def table(prefix):
return '%s_%s' % (prefix, K('HPHP::(anonymous namespace)::repoSchema').string())
#------------------------------------------------------------------------------
# Decoder.
class Decoder(object):
def __init__(self, buf):
self.buf = buf
self.off = 0
self.struct = struct.Struct('b')
def next_byte(self):
return self.struct.unpack_from(self.buf[self.off:])[0]
def decode(self):
remaining = len(self.buf) - self.off
max_len = 10 # int(V('folly::kMaxVarintLength64'))
limit = min(remaining, max_len)
i, val, shift = 0, 0, 0
b = self.next_byte()
while i < limit and b < 0:
val |= (b & 0x7f) << shift
self.off += 1
shift += 7
b = self.next_byte()
if i == limit:
raise BufferError('Invalid varint value.')
val |= (b & 0x7f) << shift
self.off += 1
return val
def finished(self):
return self.off == len(self.buf)
#------------------------------------------------------------------------------
# `repo' commands.
class RepoCommand(gdb.Command):
"""Point GDB to HHVM's repos to fetch auxiliary data."""
def __init__(self):
super(RepoCommand, self).__init__('repo', gdb.COMMAND_FILES,
gdb.COMPLETE_NONE, True)
class RepoShowCommand(gdb.Command):
"""List the user-specified repos."""
def __init__(self):
super(RepoShowCommand, self).__init__('repo show', gdb.COMMAND_FILES)
@errorwrap
def invoke(self, args, from_tty):
global _paths
print('Central repo: %s' % '<none>' if _paths[0] is None else _paths[0])
print('Local repo: %s' % '<none>' if _paths[1] is None else _paths[1])
class RepoSetCentralCommand(gdb.Command):
"""Set the central repo."""
def __init__(self):
super(RepoSetCentralCommand, self).__init__('repo set-central',
gdb.COMMAND_FILES)
@errorwrap
def invoke(self, args, from_tty):
argv = gdb.string_to_argv(args)
if len(argv) != 1:
print('Usage: repo set-central path/to/repo')
return
set(V('HPHP::RepoIdCentral'), argv[0])
print('Set central repo to %s' % argv[0])
class RepoSetLocalCommand(gdb.Command):
"""Set the local repo."""
def __init__(self):
super(RepoSetLocalCommand, self).__init__('repo set-local',
gdb.COMMAND_FILES)
@errorwrap
def invoke(self, args, from_tty):
argv = gdb.string_to_argv(args)
if len(argv) != 1:
print('Usage: repo set-local path/to/repo')
return
set(V('HPHP::RepoIdLocal'), argv[0])
print('Set local repo to %s' % argv[0])
RepoCommand()
RepoShowCommand()
RepoSetCentralCommand()
RepoSetLocalCommand()