old_contents: #!/usr/bin/env python
  #
  # h2olog - A BPF-backed request logging client for the H2O server.
  #
  # USAGE: $ sudo h2olog -p $(pgrep -o h2o)
  #
  # Copyright 2019 Fastly, Toru Maesaka
  
  from bcc import BPF, USDT
  import getopt, sys
  
  bpf = """
  #define MAX_STR_LEN 128
  
  /*
   * "req_line_t" represents an individual log line for a given request.
   * This structure is pushed into the BPF ring buffer for later collection
   * by the user-space script (Python part of this script).
   */
  struct req_line_t {
      u64 conn_id;
      u64 req_id;
      u32 http_version;
      u64 header_name_len;
      u64 header_value_len;
      char header_name[MAX_STR_LEN];
      char header_value[MAX_STR_LEN];
  };
  BPF_PERF_OUTPUT(reqbuf);
  
  int trace_receive_req(void *ctx) {
      struct req_line_t line = {};
      uint64_t conn_id, req_id;
      uint32_t http_version;
  
      bpf_usdt_readarg(1, ctx, &line.conn_id);
      bpf_usdt_readarg(2, ctx, &line.req_id);
      bpf_usdt_readarg(3, ctx, &line.http_version);
  
      if (reqbuf.perf_submit(ctx, &line, sizeof(line)) < 0)
          bpf_trace_printk("failed to perf_submit\\n");
  
      return 0;
  }
  
  int trace_receive_req_header(void *ctx) {
      return 0;
  }
  """
  
  def print_req_line(cpu, data, size):
      line = b["reqbuf"].event(data)
      if line.http_version:
          v = "HTTP/%d.%d" % (line.http_version / 256, line.http_version % 256)
          print("%u %u: %s" % (line.conn_id, line.req_id, v))
  
  try:
      h2o_pid = 0
      opts, args = getopt.getopt(sys.argv[1:], 'p:')
      for opt, arg in opts:
          if opt == "-p":
              h2o_pid = arg
  except getopt.error as msg:
      print(msg)
      sys.exit(2)
  
  if h2o_pid == 0:
      sys.exit("USAGE: h2olog -p PID")
  
  u = USDT(pid=int(h2o_pid))
  u.enable_probe(probe="receive_request", fn_name="trace_receive_req")
  u.enable_probe(probe="receive_request_header", fn_name="trace_receive_req_header")
  
  b = BPF(text=bpf, usdt_contexts=[u])
  b["reqbuf"].open_perf_buffer(print_req_line)
  
  while 1:
      try:
          b.perf_buffer_poll()
      except KeyboardInterrupt:
          exit()
  
new_contents: #!/usr/bin/env python
  #
  # h2olog - A BPF-backed request logging client for the H2O server.
  #
  # USAGE: $ sudo h2olog -p $(pgrep -o h2o)
  #
  # Copyright 2019 Fastly, Toru Maesaka
  
  from bcc import BPF, USDT
  import getopt, sys
  
  bpf = """
  #define MAX_STR_LEN 128
  
  /*
   * "req_line_t" represents an individual log line for a given request.
   * This structure is pushed into the BPF ring buffer for later collection
   * by the user-space script (Python part of this script).
   */
  struct req_line_t {
      u64 conn_id;
      u64 req_id;
      u32 http_version;
      u64 header_name_len;
      u64 header_value_len;
      char header_name[MAX_STR_LEN];
      char header_value[MAX_STR_LEN];
  };
  BPF_PERF_OUTPUT(reqbuf);
  
  int trace_receive_req(struct pt_regs *ctx) {
      struct req_line_t line = {};
      uint64_t conn_id, req_id;
      uint32_t http_version;
  
      bpf_usdt_readarg(1, ctx, &line.conn_id);
      bpf_usdt_readarg(2, ctx, &line.req_id);
      bpf_usdt_readarg(3, ctx, &line.http_version);
  
      if (reqbuf.perf_submit(ctx, &line, sizeof(line)) < 0)
          bpf_trace_printk("failed to perf_submit\\n");
  
      return 0;
  }
  
  int trace_receive_req_header(void *ctx) {
      return 0;
  }
  """
  
  def print_req_line(cpu, data, size):
      line = b["reqbuf"].event(data)
      if line.http_version:
          v = "HTTP/%d.%d" % (line.http_version / 256, line.http_version % 256)
          print("%u %u: %s" % (line.conn_id, line.req_id, v))
  
  try:
      h2o_pid = 0
      opts, args = getopt.getopt(sys.argv[1:], 'p:')
      for opt, arg in opts:
          if opt == "-p":
              h2o_pid = arg
  except getopt.error as msg:
      print(msg)
      sys.exit(2)
  
  if h2o_pid == 0:
      sys.exit("USAGE: h2olog -p PID")
  
  u = USDT(pid=int(h2o_pid))
  u.enable_probe(probe="receive_request", fn_name="trace_receive_req")
  u.enable_probe(probe="receive_request_header", fn_name="trace_receive_req_header")
  
  b = BPF(text=bpf, usdt_contexts=[u])
  b["reqbuf"].open_perf_buffer(print_req_line)
  
  while 1:
      try:
          b.perf_buffer_poll()
      except KeyboardInterrupt:
          exit()
  
subject: use a pt_regs pointer instead of a void one