Skip to content

Commit 041f471

Browse files
committed
Create GDB pretty printer for offset_ptr, and implement the Unordered customization points
1 parent 9fc4ee7 commit 041f471

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2024 Braden Ganetsky
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# https://www.boost.org/LICENSE_1_0.txt
4+
5+
import gdb.printing
6+
7+
class BoostInterprocessOffsetPtrPrinter:
8+
def __init__(self, val):
9+
self.val = val
10+
11+
def to_string(self):
12+
return f"{BoostInterprocessOffsetPtrPrinter.get(self.val)}"
13+
14+
# This is a simplified and inlined version of `offset_ptr::get()`
15+
def get(offset_ptr):
16+
offset = offset_ptr["internal"]["m_offset"]
17+
pointer = offset_ptr.type.template_argument(0).pointer()
18+
if offset == 1:
19+
return gdb.Value(0).cast(pointer) # nullptr
20+
else:
21+
unsigned_char_pointer = gdb.lookup_type("unsigned char").pointer()
22+
this = offset_ptr.address
23+
return (this.cast(unsigned_char_pointer) + offset).cast(pointer)
24+
25+
def boost_to_address(offset_ptr):
26+
return BoostInterprocessOffsetPtrPrinter.get(offset_ptr)
27+
28+
# This is a simplified and inlined version of `offset_ptr::operator+=()`
29+
def boost_next(raw_ptr, offset):
30+
unsigned_char_pointer = gdb.lookup_type("unsigned char").pointer()
31+
pointer = raw_ptr.type
32+
aa = raw_ptr.cast(unsigned_char_pointer)
33+
bb = offset * pointer.target().sizeof
34+
return (aa + bb).cast(pointer)
35+
36+
def boost_interprocess_build_pretty_printer():
37+
pp = gdb.printing.RegexpCollectionPrettyPrinter("boost_interprocess")
38+
39+
pp.add_printer("boost::interprocess::offset_ptr", "^boost::interprocess::offset_ptr<.*>$", BoostInterprocessOffsetPtrPrinter)
40+
41+
return pp
42+
43+
gdb.printing.register_pretty_printer(gdb.current_objfile(), boost_interprocess_build_pretty_printer())
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2024 Braden Ganetsky
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
5+
// Generated on 2024-08-16T22:13:13
6+
7+
#ifndef BOOST_INTERPROCESS_INTERPROCESS_PRINTERS_HPP
8+
#define BOOST_INTERPROCESS_INTERPROCESS_PRINTERS_HPP
9+
10+
#ifndef BOOST_ALL_NO_EMBEDDED_GDB_SCRIPTS
11+
#if defined(__ELF__)
12+
#ifdef __clang__
13+
#pragma clang diagnostic push
14+
#pragma clang diagnostic ignored "-Woverlength-strings"
15+
#endif
16+
__asm__(".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
17+
".ascii \"\\4gdb.inlined-script.BOOST_INTERPROCESS_INTERPROCESS_PRINTERS_HPP\\n\"\n"
18+
".ascii \"import gdb.printing\\n\"\n"
19+
20+
".ascii \"class BoostInterprocessOffsetPtrPrinter:\\n\"\n"
21+
".ascii \" def __init__(self, val):\\n\"\n"
22+
".ascii \" self.val = val\\n\"\n"
23+
24+
".ascii \" def to_string(self):\\n\"\n"
25+
".ascii \" return f\\\"{BoostInterprocessOffsetPtrPrinter.get(self.val)}\\\"\\n\"\n"
26+
27+
".ascii \" # This is a simplified and inlined version of `offset_ptr::get()`\\n\"\n"
28+
".ascii \" def get(offset_ptr):\\n\"\n"
29+
".ascii \" offset = offset_ptr[\\\"internal\\\"][\\\"m_offset\\\"]\\n\"\n"
30+
".ascii \" pointer = offset_ptr.type.template_argument(0).pointer()\\n\"\n"
31+
".ascii \" if offset == 1:\\n\"\n"
32+
".ascii \" return gdb.Value(0).cast(pointer) # nullptr\\n\"\n"
33+
".ascii \" else:\\n\"\n"
34+
".ascii \" unsigned_char_pointer = gdb.lookup_type(\\\"unsigned char\\\").pointer()\\n\"\n"
35+
".ascii \" this = offset_ptr.address\\n\"\n"
36+
".ascii \" return (this.cast(unsigned_char_pointer) + offset).cast(pointer)\\n\"\n"
37+
38+
".ascii \" def boost_to_address(offset_ptr):\\n\"\n"
39+
".ascii \" return BoostInterprocessOffsetPtrPrinter.get(offset_ptr)\\n\"\n"
40+
41+
".ascii \" # This is a simplified and inlined version of `offset_ptr::operator+=()`\\n\"\n"
42+
".ascii \" def boost_next(raw_ptr, offset):\\n\"\n"
43+
".ascii \" unsigned_char_pointer = gdb.lookup_type(\\\"unsigned char\\\").pointer()\\n\"\n"
44+
".ascii \" pointer = raw_ptr.type\\n\"\n"
45+
".ascii \" aa = raw_ptr.cast(unsigned_char_pointer)\\n\"\n"
46+
".ascii \" bb = offset * pointer.target().sizeof\\n\"\n"
47+
".ascii \" return (aa + bb).cast(pointer)\\n\"\n"
48+
49+
".ascii \"def boost_interprocess_build_pretty_printer():\\n\"\n"
50+
".ascii \" pp = gdb.printing.RegexpCollectionPrettyPrinter(\\\"boost_interprocess\\\")\\n\"\n"
51+
52+
".ascii \" pp.add_printer(\\\"boost::interprocess::offset_ptr\\\", \\\"^boost::interprocess::offset_ptr<.*>$\\\", BoostInterprocessOffsetPtrPrinter)\\n\"\n"
53+
54+
".ascii \" return pp\\n\"\n"
55+
56+
".ascii \"gdb.printing.register_pretty_printer(gdb.current_objfile(), boost_interprocess_build_pretty_printer())\\n\"\n"
57+
58+
".byte 0\n"
59+
".popsection\n");
60+
#ifdef __clang__
61+
#pragma clang diagnostic pop
62+
#endif
63+
#endif // defined(__ELF__)
64+
#endif // !defined(BOOST_ALL_NO_EMBEDDED_GDB_SCRIPTS)
65+
66+
#endif // !defined(BOOST_INTERPROCESS_INTERPROCESS_PRINTERS_HPP)

include/boost/interprocess/offset_ptr.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <boost/type_traits/is_unsigned.hpp>
2929

3030
#include <boost/interprocess/interprocess_fwd.hpp>
31+
#include <boost/interprocess/interprocess_printers.hpp>
3132
#include <boost/interprocess/detail/utilities.hpp>
3233
#include <boost/interprocess/detail/cast_tags.hpp>
3334
#include <boost/interprocess/detail/mpl.hpp>

0 commit comments

Comments
 (0)