• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Alan-Jowett / ebpf-verifier / 18658728485

18 Oct 2025 05:56PM UTC coverage: 88.47% (+0.4%) from 88.11%
18658728485

push

github

elazarg
Bump external/bpf_conformance from `8f3c2fe` to `6fa6a20`

Bumps [external/bpf_conformance](https://github.com/Alan-Jowett/bpf_conformance) from `8f3c2fe` to `6fa6a20`.
- [Release notes](https://github.com/Alan-Jowett/bpf_conformance/releases)
- [Commits](https://github.com/Alan-Jowett/bpf_conformance/compare/8f3c2fe88...<a class=hub.com/Alan-Jowett/ebpf-verifier/commit/6fa6a20ac6fd3612ea9338312a67408687b9f06b">6fa6a20ac)

---
updated-dependencies:
- dependency-name: external/bpf_conformance
  dependency-version: 6fa6a20ac6fd3612ea9338312a67408687b9f06b
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

8954 of 10121 relevant lines covered (88.47%)

18293099.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.25
/src/asm_ostream.cpp
1
// Copyright (c) Prevail Verifier contributors.
2
// SPDX-License-Identifier: MIT
3
#include <fstream>
4
#include <iomanip>
5
#include <iostream>
6
#include <variant>
7
#include <vector>
8

9
#include "arith/num_big.hpp"
10
#include "arith/variable.hpp"
11
#include "asm_syntax.hpp"
12
#include "cfg/cfg.hpp"
13
#include "crab/fwd_analyzer.hpp"
14
#include "crab/interval.hpp"
15
#include "crab/type_encoding.hpp"
16
#include "crab/var_registry.hpp"
17
#include "crab_verifier.hpp"
18
#include "helpers.hpp"
19
#include "platform.hpp"
20
#include "spec_type_descriptors.hpp"
21

22
using std::optional;
23
using std::string;
24
using std::vector;
25

26
namespace prevail {
27

28
std::ostream& operator<<(std::ostream& o, const Interval& interval) {
854✔
29
    if (interval.is_bottom()) {
854✔
30
        o << "_|_";
×
31
    } else {
32
        o << "[" << interval._lb << ", " << interval._ub << "]";
854✔
33
    }
34
    return o;
854✔
35
}
36
std::ostream& operator<<(std::ostream& o, const Number& z) { return o << z._n.str(); }
354,112✔
37

38
std::string Number::to_string() const { return _n.str(); }
×
39

40
std::string Interval::to_string() const {
×
41
    std::ostringstream s;
×
42
    s << *this;
×
43
    return s.str();
×
44
}
×
45

46
std::ostream& operator<<(std::ostream& os, const Label& label) {
1,580✔
47
    if (label == Label::entry) {
1,580✔
48
        return os << "entry";
6✔
49
    }
50
    if (label == Label::exit) {
1,574✔
51
        return os << "exit";
6✔
52
    }
53
    if (!label.stack_frame_prefix.empty()) {
1,568✔
54
        os << label.stack_frame_prefix << STACK_FRAME_DELIMITER;
330✔
55
    }
56
    os << label.from;
1,568✔
57
    if (label.to != -1) {
1,568✔
58
        os << ":" << label.to;
50✔
59
    }
60
    if (!label.special_label.empty()) {
1,568✔
61
        os << " (" << label.special_label << ")";
20✔
62
    }
63
    return os;
784✔
64
}
65

66
string to_string(Label const& label) {
1,534✔
67
    std::stringstream str;
1,534✔
68
    str << label;
1,534✔
69
    return str.str();
3,068✔
70
}
1,534✔
71

72
struct LineInfoPrinter {
73
    std::ostream& os;
74
    std::string previous_source_line;
75

76
    void print_line_info(const Label& label) {
×
77
        if (thread_local_options.verbosity_opts.print_line_info) {
×
78
            const auto& line_info_map = thread_local_program_info.get().line_info;
×
79
            const auto& line_info = line_info_map.find(label.from);
×
80
            // Print line info only once.
81
            if (line_info != line_info_map.end() && line_info->second.source_line != previous_source_line) {
×
82
                os << "\n" << line_info->second << "\n";
×
83
                previous_source_line = line_info->second.source_line;
×
84
            }
85
        }
86
    }
×
87
};
88

89
void print_jump(std::ostream& o, const std::string& direction, const std::set<Label>& labels) {
×
90
    auto [it, et] = std::pair{labels.begin(), labels.end()};
×
91
    if (it != et) {
×
92
        o << "  " << direction << " ";
×
93
        while (it != et) {
×
94
            o << *it;
×
95
            ++it;
×
96
            if (it == et) {
×
97
                o << ";";
×
98
            } else {
99
                o << ",";
×
100
            }
101
        }
102
    }
103
    o << "\n";
×
104
}
×
105

106
void print_program(const Program& prog, std::ostream& os, const bool simplify, const printfunc& prefunc,
×
107
                   const printfunc& postfunc) {
108
    LineInfoPrinter printer{os};
×
109
    for (const BasicBlock& bb : BasicBlock::collect_basic_blocks(prog.cfg(), simplify)) {
×
110
        prefunc(os, bb.first_label());
×
111
        print_jump(os, "from", prog.cfg().parents_of(bb.first_label()));
×
112
        os << bb.first_label() << ":\n";
×
113
        for (const Label& label : bb) {
×
114
            printer.print_line_info(label);
×
115
            for (const auto& pre : prog.assertions_at(label)) {
×
116
                os << "  " << "assert " << pre << ";\n";
×
117
            }
×
118
            os << "  " << prog.instruction_at(label) << ";\n";
×
119
        }
120
        print_jump(os, "goto", prog.cfg().children_of(bb.last_label()));
×
121
        postfunc(os, bb.last_label());
×
122
    }
×
123
    os << "\n";
×
124
}
×
125

126
static void nop(std::ostream&, const Label&) {}
×
127

128
void print_program(const Program& prog, std::ostream& os, const bool simplify) {
×
129
    print_program(prog, os, simplify, nop, nop);
×
130
}
×
131

132
void print_dot(const Program& prog, std::ostream& out) {
×
133
    out << "digraph program {\n";
×
134
    out << "    node [shape = rectangle];\n";
×
135
    for (const auto& label : prog.labels()) {
×
136
        out << "    \"" << label << "\"[xlabel=\"" << label << "\",label=\"";
×
137

138
        for (const auto& pre : prog.assertions_at(label)) {
×
139
            out << "assert " << pre << "\\l";
×
140
        }
×
141
        out << prog.instruction_at(label) << "\\l";
×
142

143
        out << "\"];\n";
×
144
        for (const Label& next : prog.cfg().children_of(label)) {
×
145
            out << "    \"" << label << "\" -> \"" << next << "\";\n";
×
146
        }
147
        out << "\n";
×
148
    }
149
    out << "}\n";
×
150
}
×
151

152
void print_dot(const Program& prog, const std::string& outfile) {
×
153
    std::ofstream out{outfile};
×
154
    if (out.fail()) {
×
155
        throw std::runtime_error(std::string("Could not open file ") + outfile);
×
156
    }
157
    print_dot(prog, out);
×
158
}
×
159

160
void print_reachability(std::ostream& os, const Report& report) {
×
161
    for (const auto& [label, notes] : report.reachability) {
×
162
        for (const auto& msg : notes) {
×
163
            os << label << ": " << msg << "\n";
×
164
        }
165
    }
166
    os << "\n";
×
167
}
×
168

169
void print_warnings(std::ostream& os, const Report& report) {
×
170
    LineInfoPrinter printer{os};
×
171
    for (const auto& [label, warnings] : report.warnings) {
×
172
        for (const auto& msg : warnings) {
×
173
            printer.print_line_info(label);
×
174
            os << label << ": " << msg << "\n";
×
175
        }
176
    }
177
    os << "\n";
×
178
}
×
179

180
void print_all_messages(std::ostream& os, const Report& report) {
×
181
    print_reachability(os, report);
×
182
    print_warnings(os, report);
×
183
}
×
184

185
void print_invariants(std::ostream& os, const Program& prog, const bool simplify, const Invariants& invariants) {
×
186
    print_program(
×
187
        prog, os, simplify,
188
        [&](std::ostream& os, const Label& label) -> void {
×
189
            os << "\nPre-invariant : " << invariants.invariants.at(label).pre << "\n";
×
190
        },
×
191
        [&](std::ostream& os, const Label& label) -> void {
×
192
            os << "\nPost-invariant : " << invariants.invariants.at(label).post << "\n";
×
193
        });
×
194
}
×
195

196
std::ostream& operator<<(std::ostream& os, const ArgSingle::Kind kind) {
74✔
197
    switch (kind) {
74✔
198
    case ArgSingle::Kind::ANYTHING: return os << "uint64_t";
14✔
199
    case ArgSingle::Kind::PTR_TO_CTX: return os << "ctx";
4✔
200
    case ArgSingle::Kind::MAP_FD: return os << "map_fd";
24✔
201
    case ArgSingle::Kind::MAP_FD_PROGRAMS: return os << "map_fd_programs";
×
202
    case ArgSingle::Kind::PTR_TO_MAP_KEY: return os << "map_key";
24✔
203
    case ArgSingle::Kind::PTR_TO_MAP_VALUE: return os << "map_value";
8✔
204
    }
205
    assert(false);
206
    return os;
207
}
208

209
std::ostream& operator<<(std::ostream& os, const ArgPair::Kind kind) {
×
210
    switch (kind) {
×
211
    case ArgPair::Kind::PTR_TO_READABLE_MEM: return os << "mem";
×
212
    case ArgPair::Kind::PTR_TO_WRITABLE_MEM: return os << "out";
×
213
    }
214
    assert(false);
215
    return os;
216
}
217

218
std::ostream& operator<<(std::ostream& os, const ArgSingle arg) {
74✔
219
    os << arg.kind << " " << arg.reg;
74✔
220
    return os;
74✔
221
}
222

223
std::ostream& operator<<(std::ostream& os, const ArgPair arg) {
×
224
    os << arg.kind;
×
225
    if (arg.or_null) {
×
226
        os << "?";
×
227
    }
228
    os << " " << arg.mem << "[" << arg.size;
×
229
    if (arg.can_be_zero) {
×
230
        os << "?";
×
231
    }
232
    os << "], uint64_t " << arg.size;
×
233
    return os;
×
234
}
235

236
std::ostream& operator<<(std::ostream& os, const Bin::Op op) {
278✔
237
    using Op = Bin::Op;
139✔
238
    switch (op) {
278✔
239
    case Op::MOV: return os;
81✔
240
    case Op::MOVSX8: return os << "s8";
×
241
    case Op::MOVSX16: return os << "s16";
×
242
    case Op::MOVSX32: return os << "s32";
×
243
    case Op::ADD: return os << "+";
70✔
244
    case Op::SUB: return os << "-";
×
245
    case Op::MUL: return os << "*";
×
246
    case Op::UDIV: return os << "/";
×
247
    case Op::SDIV: return os << "s/";
×
248
    case Op::UMOD: return os << "%";
×
249
    case Op::SMOD: return os << "s%";
×
250
    case Op::OR: return os << "|";
×
251
    case Op::AND: return os << "&";
30✔
252
    case Op::LSH: return os << "<<";
12✔
253
    case Op::RSH: return os << ">>";
×
254
    case Op::ARSH: return os << ">>>";
2✔
255
    case Op::XOR: return os << "^";
2✔
256
    }
257
    assert(false);
258
    return os;
259
}
260

261
std::ostream& operator<<(std::ostream& os, const Condition::Op op) {
222✔
262
    using Op = Condition::Op;
111✔
263
    switch (op) {
222✔
264
    case Op::EQ: return os << "==";
38✔
265
    case Op::NE: return os << "!=";
10✔
266
    case Op::SET: return os << "&==";
×
267
    case Op::NSET: return os << "&!="; // not in ebpf
×
268
    case Op::LT: return os << "<";     // TODO: os << "u<";
124✔
269
    case Op::LE: return os << "<=";    // TODO: os << "u<=";
12✔
270
    case Op::GT: return os << ">";     // TODO: os << "u>";
22✔
271
    case Op::GE: return os << ">=";    // TODO: os << "u>=";
6✔
272
    case Op::SLT: return os << "s<";
4✔
273
    case Op::SLE: return os << "s<=";
×
274
    case Op::SGT: return os << "s>";
4✔
275
    case Op::SGE: return os << "s>=";
2✔
276
    }
277
    assert(false);
278
    return os;
279
}
280

281
static string size(const int w) { return string("u") + std::to_string(w * 8); }
460✔
282

283
// ReSharper disable CppMemberFunctionMayBeConst
284
struct AssertionPrinterVisitor {
285
    std::ostream& _os;
286

287
    void operator()(ValidStore const& a) {
2✔
288
        _os << a.mem << ".type != stack -> " << TypeConstraint{a.val, TypeGroup::number};
2✔
289
    }
2✔
290

291
    void operator()(ValidAccess const& a) {
48,862✔
292
        if (a.or_null) {
48,862✔
293
            _os << "(" << TypeConstraint{a.reg, TypeGroup::number} << " and " << a.reg << ".value == 0) or ";
3,360✔
294
        }
295
        _os << "valid_access(" << a.reg << ".offset";
48,862✔
296
        if (a.offset > 0) {
48,862✔
297
            _os << "+" << a.offset;
30,964✔
298
        } else if (a.offset < 0) {
17,898✔
299
            _os << a.offset;
112✔
300
        }
301

302
        if (a.width == Value{Imm{0}}) {
48,862✔
303
            // a.width == 0, meaning we only care it's an in-bound pointer,
304
            // so it can be compared with another pointer to the same region.
305
            _os << ") for comparison/subtraction";
4,184✔
306
        } else {
307
            _os << ", width=" << a.width << ") for ";
44,678✔
308
            if (a.access_type == AccessType::read) {
44,678✔
309
                _os << "read";
33,112✔
310
            } else {
311
                _os << "write";
11,566✔
312
            }
313
        }
314
    }
48,862✔
315

316
    void operator()(const BoundedLoopCount& a) {
32✔
317
        _os << variable_registry->loop_counter(to_string(a.name)) << " < " << a.limit;
32✔
318
    }
32✔
319

320
    void operator()(ValidSize const& a) {
4,206✔
321
        const auto op = a.can_be_zero ? " >= " : " > ";
4,206✔
322
        _os << a.reg << ".value" << op << 0;
4,206✔
323
    }
4,206✔
324

325
    void operator()(ValidCall const& a) {
2✔
326
        const EbpfHelperPrototype proto = thread_local_program_info->platform->get_helper_prototype(a.func);
2✔
327
        _os << "valid call(" << proto.name << ")";
2✔
328
    }
2✔
329

330
    void operator()(ValidMapKeyValue const& a) {
132✔
331
        _os << "within stack(" << a.access_reg << ":" << (a.key ? "key_size" : "value_size") << "(" << a.map_fd_reg
168✔
332
            << "))";
132✔
333
    }
132✔
334

335
    void operator()(ZeroCtxOffset const& a) {
5,236✔
336
        _os << variable_registry->reg(DataKind::ctx_offsets, a.reg.v) << " == 0";
5,236✔
337
    }
5,236✔
338

339
    void operator()(Comparable const& a) {
2,212✔
340
        if (a.or_r2_is_number) {
2,212✔
341
            _os << TypeConstraint{a.r2, TypeGroup::number} << " or ";
366✔
342
        }
343
        _os << variable_registry->type_reg(a.r1.v) << " == " << variable_registry->type_reg(a.r2.v) << " in "
2,212✔
344
            << TypeGroup::singleton_ptr;
2,212✔
345
    }
2,212✔
346

347
    void operator()(Addable const& a) {
4✔
348
        _os << TypeConstraint{a.ptr, TypeGroup::pointer} << " -> " << TypeConstraint{a.num, TypeGroup::number};
8✔
349
    }
4✔
350

351
    void operator()(ValidDivisor const& a) { _os << a.reg << " != 0"; }
76✔
352

353
    void operator()(TypeConstraint const& tc) {
2,164✔
354
        const string cmp_op = is_singleton_type(tc.types) ? "==" : "in";
2,189✔
355
        _os << variable_registry->type_reg(tc.reg.v) << " " << cmp_op << " " << tc.types;
2,164✔
356
    }
2,164✔
357

358
    void operator()(FuncConstraint const& fc) { _os << variable_registry->type_reg(fc.reg.v) << " is helper"; }
6✔
359
};
360

361
// ReSharper disable CppMemberFunctionMayBeConst
362
struct CommandPrinterVisitor {
363
    std::ostream& os_;
364

365
    void visit(const auto& item) { std::visit(*this, item); }
366

367
    void operator()(Undefined const& a) { os_ << "Undefined{" << a.opcode << "}"; }
×
368

369
    void operator()(LoadMapFd const& b) { os_ << b.dst << " = map_fd " << b.mapfd; }
24✔
370

371
    void operator()(LoadMapAddress const& b) { os_ << b.dst << " = map_val(" << b.mapfd << ") + " << b.offset; }
×
372

373
    // llvm-objdump uses "w<number>" for 32-bit operations and "r<number>" for 64-bit operations.
374
    // We use the same convention here for consistency.
375
    static std::string reg_name(Reg const& a, const bool is64) { return ((is64) ? "r" : "w") + std::to_string(a.v); }
417✔
376

377
    void operator()(Bin const& b) {
278✔
378
        os_ << reg_name(b.dst, b.is64) << " " << b.op << "= " << b.v;
417✔
379
        if (b.lddw) {
278✔
380
            os_ << " ll";
2✔
381
        }
382
    }
278✔
383

384
    void operator()(Un const& b) {
12✔
385
        os_ << b.dst << " = ";
12✔
386
        switch (b.op) {
12✔
387
        case Un::Op::BE16: os_ << "be16 "; break;
2✔
388
        case Un::Op::BE32: os_ << "be32 "; break;
2✔
389
        case Un::Op::BE64: os_ << "be64 "; break;
2✔
390
        case Un::Op::LE16: os_ << "le16 "; break;
2✔
391
        case Un::Op::LE32: os_ << "le32 "; break;
2✔
392
        case Un::Op::LE64: os_ << "le64 "; break;
2✔
393
        case Un::Op::SWAP16: os_ << "swap16 "; break;
×
394
        case Un::Op::SWAP32: os_ << "swap32 "; break;
×
395
        case Un::Op::SWAP64: os_ << "swap64 "; break;
×
396
        case Un::Op::NEG: os_ << "-"; break;
×
397
        }
398
        os_ << b.dst;
12✔
399
    }
12✔
400

401
    void operator()(Call const& call) {
70✔
402
        os_ << "r0 = " << call.name << ":" << call.func << "(";
70✔
403
        for (uint8_t r = 1; r <= 5; r++) {
144✔
404
            // Look for a singleton.
405
            auto single = std::ranges::find_if(call.singles, [r](const ArgSingle arg) { return arg.reg.v == r; });
372✔
406
            if (single != call.singles.end()) {
144✔
407
                if (r > 1) {
74✔
408
                    os_ << ", ";
48✔
409
                }
410
                os_ << *single;
74✔
411
                continue;
74✔
412
            }
413

414
            // Look for the start of a pair.
415
            auto pair = std::ranges::find_if(call.pairs, [r](const ArgPair arg) { return arg.mem.v == r; });
70✔
416
            if (pair != call.pairs.end()) {
70✔
417
                if (r > 1) {
×
418
                    os_ << ", ";
×
419
                }
420
                os_ << *pair;
×
421
                r++;
×
422
                continue;
×
423
            }
424

425
            // Not found.
426
            break;
70✔
427
        }
428
        os_ << ")";
70✔
429
    }
70✔
430

431
    void operator()(CallLocal const& call) { os_ << "call <" << to_string(call.target) << ">"; }
×
432

433
    void operator()(Callx const& callx) { os_ << "callx " << callx.func; }
×
434

435
    void operator()(Exit const& b) { os_ << "exit"; }
50✔
436

437
    void operator()(Jmp const& b) {
×
438
        // A "standalone" jump Instruction.
439
        // Print the label without offset calculations.
440
        if (b.cond) {
×
441
            os_ << "if ";
×
442
            print(*b.cond);
×
443
            os_ << " ";
×
444
        }
445
        os_ << "goto label <" << to_string(b.target) << ">";
×
446
    }
×
447

448
    void operator()(Jmp const& b, const int offset) {
54✔
449
        const string sign = offset > 0 ? "+" : "";
54✔
450
        const string target = sign + std::to_string(offset) + " <" + to_string(b.target) + ">";
108✔
451

452
        if (b.cond) {
54✔
453
            os_ << "if ";
40✔
454
            print(*b.cond);
40✔
455
            os_ << " ";
40✔
456
        }
457
        os_ << "goto " << target;
54✔
458
    }
54✔
459

460
    void operator()(Packet const& b) {
×
461
        /* Direct packet access, R0 = *(uint *) (skb->data + imm32) */
462
        /* Indirect packet access, R0 = *(uint *) (skb->data + src_reg + imm32) */
463
        const string s = size(b.width);
×
464
        os_ << "r0 = ";
×
465
        os_ << "*(" << s << " *)skb[";
×
466
        if (b.regoffset) {
×
467
            os_ << *b.regoffset;
×
468
        }
469
        if (b.offset != 0) {
×
470
            if (b.regoffset) {
×
471
                os_ << " + ";
×
472
            }
473
            os_ << b.offset;
×
474
        }
475
        os_ << "]";
×
476
    }
×
477

478
    void print(Deref const& access) {
184✔
479
        const string sign = access.offset < 0 ? " - " : " + ";
212✔
480
        const int offset = std::abs(access.offset); // what about INT_MIN?
184✔
481
        os_ << "*(" << size(access.width) << " *)";
276✔
482
        os_ << "(" << access.basereg << sign << offset << ")";
184✔
483
    }
184✔
484

485
    void print(Condition const& cond) {
222✔
486
        os_ << cond.left << " " << ((!cond.is64) ? "w" : "") << cond.op << " " << cond.right;
261✔
487
    }
222✔
488

489
    void operator()(Mem const& b) {
184✔
490
        if (b.is_load) {
184✔
491
            os_ << b.value << " = ";
44✔
492
        }
493
        print(b.access);
184✔
494
        if (!b.is_load) {
184✔
495
            os_ << " = " << b.value;
140✔
496
        }
497
    }
184✔
498

499
    void operator()(Atomic const& b) {
×
500
        os_ << "lock ";
×
501
        print(b.access);
×
502
        os_ << " ";
×
503
        bool showfetch = true;
×
504
        switch (b.op) {
×
505
        case Atomic::Op::ADD: os_ << "+"; break;
×
506
        case Atomic::Op::OR: os_ << "|"; break;
×
507
        case Atomic::Op::AND: os_ << "&"; break;
×
508
        case Atomic::Op::XOR: os_ << "^"; break;
×
509
        case Atomic::Op::XCHG:
×
510
            os_ << "x";
×
511
            showfetch = false;
×
512
            break;
×
513
        case Atomic::Op::CMPXCHG:
×
514
            os_ << "cx";
×
515
            showfetch = false;
×
516
            break;
×
517
        }
518
        os_ << "= " << b.valreg;
×
519

520
        if (showfetch && b.fetch) {
×
521
            os_ << " fetch";
×
522
        }
523
    }
×
524

525
    void operator()(Assume const& b) {
182✔
526
        os_ << "assume ";
182✔
527
        print(b.cond);
182✔
528
    }
182✔
529

530
    void operator()(IncrementLoopCounter const& a) {
×
531
        os_ << variable_registry->loop_counter(to_string(a.name)) << "++";
×
532
    }
×
533
};
534
// ReSharper restore CppMemberFunctionMayBeConst
535

536
std::ostream& operator<<(std::ostream& os, Instruction const& ins) {
184✔
537
    std::visit(CommandPrinterVisitor{os}, ins);
92✔
538
    return os;
92✔
539
}
540

541
string to_string(Instruction const& ins) {
184✔
542
    std::stringstream str;
184✔
543
    str << ins;
184✔
544
    return str.str();
368✔
545
}
184✔
546

547
std::ostream& operator<<(std::ostream& os, const Assertion& a) {
62,934✔
548
    std::visit(AssertionPrinterVisitor{os}, a);
32,434✔
549
    return os;
32,434✔
550
}
551

552
string to_string(Assertion const& constraint) {
61,000✔
553
    std::stringstream str;
61,000✔
554
    str << constraint;
61,000✔
555
    return str.str();
122,000✔
556
}
61,000✔
557

558
auto get_labels(const InstructionSeq& insts) {
38✔
559
    Pc pc = 0;
38✔
560
    std::map<Label, Pc> pc_of_label;
38✔
561
    for (const auto& [label, inst, _] : insts) {
708✔
562
        pc_of_label[label] = pc;
670✔
563
        pc += size(inst);
670✔
564
    }
565
    return pc_of_label;
38✔
566
}
×
567

568
void print(const InstructionSeq& insts, std::ostream& out, const std::optional<const Label>& label_to_print,
38✔
569
           const bool print_line_info) {
570
    const auto pc_of_label = get_labels(insts);
38✔
571
    Pc pc = 0;
38✔
572
    std::string previous_source;
38✔
573
    CommandPrinterVisitor visitor{out};
38✔
574
    for (const LabeledInstruction& labeled_inst : insts) {
708✔
575
        const auto& [label, ins, line_info] = labeled_inst;
670✔
576
        if (!label_to_print.has_value() || label == label_to_print) {
670✔
577
            if (line_info.has_value() && print_line_info) {
670✔
578
                auto& [file, source, line, column] = line_info.value();
×
579
                // Only decorate the first instruction associated with a source line.
580
                if (source != previous_source) {
×
581
                    out << line_info.value();
×
582
                    previous_source = source;
×
583
                }
584
            }
585
            if (label.isjump()) {
670✔
586
                out << "\n";
×
587
                out << label << ":\n";
×
588
            }
589
            if (label_to_print.has_value()) {
670✔
590
                out << pc << ": ";
×
591
            } else {
592
                out << std::setw(8) << pc << ":\t";
670✔
593
            }
594
            if (const auto jmp = std::get_if<Jmp>(&ins)) {
670✔
595
                if (!pc_of_label.contains(jmp->target)) {
54✔
596
                    throw std::runtime_error(string("Cannot find label ") + to_string(jmp->target));
×
597
                }
598
                const Pc target_pc = pc_of_label.at(jmp->target);
54✔
599
                visitor(*jmp, target_pc - static_cast<int>(pc) - 1);
54✔
600
            } else {
601
                std::visit(visitor, ins);
616✔
602
            }
603
            out << "\n";
670✔
604
        }
605
        pc += size(ins);
670✔
606
    }
607
}
38✔
608

609
std::ostream& operator<<(std::ostream& o, const EbpfMapDescriptor& desc) {
28✔
610
    return o << "(" << "original_fd = " << desc.original_fd << ", " << "inner_map_fd = " << desc.inner_map_fd << ", "
28✔
611
             << "type = " << desc.type << ", " << "max_entries = " << desc.max_entries << ", "
28✔
612
             << "value_size = " << desc.value_size << ", " << "key_size = " << desc.key_size << ")";
28✔
613
}
614

615
void print_map_descriptors(const std::vector<EbpfMapDescriptor>& descriptors, std::ostream& o) {
38✔
616
    int i = 0;
38✔
617
    for (const auto& desc : descriptors) {
66✔
618
        o << "map " << i << ":" << desc << "\n";
28✔
619
        i++;
28✔
620
    }
621
}
38✔
622

623
std::ostream& operator<<(std::ostream& os, const btf_line_info_t& line_info) {
×
624
    os << "; " << line_info.file_name << ":" << line_info.line_number << "\n";
×
625
    os << "; " << line_info.source_line << "\n";
×
626
    return os;
×
627
}
628
} // namespace prevail
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc