MCPcopy Create free account
hub / github.com/bloomberg/pystack / CodeObject

Method CodeObject

src/pystack/_pystack/pycode.cpp:191–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191CodeObject::CodeObject(
192 const std::shared_ptr<const AbstractProcessManager>& manager,
193 remote_addr_t addr,
194 uintptr_t lasti,
195 int tlbc_index)
196{
197 LOG(DEBUG) << std::hex << std::showbase << "Copying code struct from address " << addr;
198 Structure<py_code_v> code(manager, addr);
199
200 remote_addr_t filename_addr = code.getField(&py_code_v::o_filename);
201 LOG(DEBUG) << std::hex << std::showbase << "Copying filename Python string from address "
202 << filename_addr;
203 d_filename = manager->getStringFromAddress(filename_addr);
204 LOG(DEBUG) << "Code object filename: " << d_filename;
205
206 remote_addr_t name_addr = code.getField(&py_code_v::o_name);
207 LOG(DEBUG) << std::hex << std::showbase << "Copying code name Python string from address "
208 << name_addr;
209 d_scope = manager->getStringFromAddress(name_addr);
210 LOG(DEBUG) << "Code object scope: " << d_filename;
211
212 LOG(DEBUG) << "Obtaining location info location";
213 d_location_info = getLocationInfo(manager, addr, code, lasti, tlbc_index);
214 LOG(DEBUG) << "Code object location info: line_range=(" << d_location_info.lineno << ", "
215 << d_location_info.end_lineno << ") column_range=(" << d_location_info.column << ", "
216 << d_location_info.end_column << ")";
217
218 d_narguments = code.getField(&py_code_v::o_argcount);
219 LOG(DEBUG) << "Code object n arguments: " << d_narguments;
220
221 LOG(DEBUG) << "Copying variable names";
222 remote_addr_t varnames_addr = code.getField(&py_code_v::o_varnames);
223 TupleObject varnames(manager, varnames_addr);
224 std::transform(
225 varnames.Items().cbegin(),
226 varnames.Items().cend(),
227 std::back_inserter(d_varnames),
228 [&](auto& addr) {
229 const std::string varname = manager->getStringFromAddress(addr);
230 LOG(DEBUG) << "Variable name found: '" << varname << "'";
231 return varname;
232 });
233}
234
235CodeObject::CodeObject(std::string filename, std::string scope, LocationInfo location_info)
236: d_filename(filename)

Callers

nothing calls this directly

Calls 3

LOGClass · 0.85
getLocationInfoFunction · 0.85
getStringFromAddressMethod · 0.80

Tested by

no test coverage detected