| 1 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | |
| 3 | """ |
| 4 | Stderr built-in backend. |
| 5 | """ |
| 6 | |
| 7 | __author__ = "Lluís Vilanova <vilanova@ac.upc.edu>" |
| 8 | __copyright__ = "Copyright 2012-2017, Lluís Vilanova <vilanova@ac.upc.edu>" |
| 9 | __license__ = "GPL version 2 or (at your option) any later version" |
| 10 | |
| 11 | __maintainer__ = "Stefan Hajnoczi" |
| 12 | __email__ = "stefanha@redhat.com" |
| 13 | |
| 14 | |
| 15 | from tracetool import out, expand_format_string |
| 16 | |
| 17 | |
| 18 | PUBLIC = True |
| 19 | CHECK_TRACE_EVENT_GET_STATE = True |
| 20 | |
| 21 | |
| 22 | def generate_h_begin(events, group): |
| 23 | out('#include "qemu/log-for-trace.h"', |
| 24 | '') |
| 25 | |
| 26 | |
| 27 | def generate_h(event, group): |
| 28 | argnames = ", ".join(event.args.names()) |
| 29 | if len(event.args) > 0: |
| 30 | argnames = ", " + argnames |
| 31 | |
| 32 | out(' if (qemu_loglevel_mask(LOG_TRACE)) {', |
| 33 | '#line %(event_lineno)d "%(event_filename)s"', |
| 34 | ' qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);', |
| 35 | '#line %(out_next_lineno)d "%(out_filename)s"', |
| 36 | ' }', |
| 37 | event_lineno=event.lineno, |
| 38 | event_filename=event.filename, |
| 39 | name=event.name, |
| 40 | fmt=event.fmt.rstrip("\n"), |
| 41 | argnames=argnames) |
| 42 | |
| 43 | |
| 44 | def generate_h_backend_dstate(event, group): |
| 45 | out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\', |
| 46 | event_id="TRACE_" + event.name.upper()) |
| 47 | |
| 48 | def generate_rs(event, group): |
| 49 | out(' let format_string = c"%(fmt)s\\n";', |
| 50 | ' if (unsafe { bindings::qemu_loglevel } & bindings::LOG_TRACE) != 0 {', |
| 51 | ' unsafe { bindings::qemu_log(format_string.as_ptr() as *const c_char, %(args)s);}', |
| 52 | ' }', |
| 53 | fmt=expand_format_string(event.fmt, event.name + " "), |
| 54 | args=event.args.rust_call_varargs()) |