<div dir="ltr">Thanks for the quick reply.<div>Inline:<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 26, 2018 at 7:29 PM Chen Jingpiao <<a href="mailto:chenjingpiao@gmail.com">chenjingpiao@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>On Wed, Jun 6, 2018 at 2:35 AM Elazar Leibovich <<a href="mailto:elazarl@gmail.com" target="_blank">elazarl@gmail.com</a>> wrote:</div><div><br></div><div>$ git apply 0001-bpf-program-printed-in-bpf_debug-compatible-format.patch</div><div><br></div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:10: trailing whitespace.</div><div><span style="white-space:pre-wrap">                </span>int i;</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:11: trailing whitespace.</div><div><span style="white-space:pre-wrap">              </span>int n = MIN(len, BPF_MAXINSNS);</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:12: trailing whitespace.</div><div><span style="white-space:pre-wrap">             </span>tprintf("%hu", n); // bpf_debug requires <len>, prefix</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:13: trailing whitespace.</div><div><span style="white-space:pre-wrap">              </span>for (i=0; i<n; i++) {</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:14: trailing whitespace.</div><div><span style="white-space:pre-wrap">                    </span>struct bpf_filter_block filter;</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:15: trailing whitespace.</div><div><span style="white-space:pre-wrap">                     </span>tfetch_mem(tcp, addr + i*sizeof(filter),</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:16: trailing whitespace.</div><div><span style="white-space:pre-wrap">                                    </span>sizeof(filter), &filter);</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:17: trailing whitespace.</div><div><span style="white-space:pre-wrap">                       </span>tprintf(",%u %u %u %u", filter.code, filter.jt,</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:18: trailing whitespace.</div><div><span style="white-space:pre-wrap">                                           </span>filter.jf, filter.k);</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:19: trailing whitespace.</div><div><span style="white-space:pre-wrap">               </span>}</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:20: trailing whitespace.</div><div><span style="white-space:pre-wrap">           </span>if (n < len)</div><div>0001-bpf-program-printed-in-bpf_debug-compatible-format.patch:21: trailing whitespace.</div><div><span style="white-space:pre-wrap">                     </span>tprints("...");</div><div>fatal: 12 lines add whitespace errors.</div><div><br></div><div>please update the patch and read guide for new contributors [1].</div></div></blockquote><div><br></div><div>Will do. I read it, and tried to follow it IIRC I used the command specified there, but would revise.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>> diff --git a/bpf_filter.c b/bpf_filter.c</div><div>> index a102e14..97f202b 100644</div><div>> --- a/bpf_filter.c</div><div>> +++ b/bpf_filter.c</div><div>> @@ -177,7 +177,18 @@ print_bpf_fprog(struct tcb *const tcp, const kernel_ulong_t addr,</div><div>>  <span style="white-space:pre-wrap">         </span>const unsigned short len, const print_bpf_filter_fn print_k)</div><div>>  {</div><div>>  <span style="white-space:pre-wrap">       </span>if (abbrev(tcp)) {</div><div>> -<span style="white-space:pre-wrap">         </span>printaddr(addr);</div><div>> +<span style="white-space:pre-wrap">           </span>int i;</div><div>> +<span style="white-space:pre-wrap">             </span>int n = MIN(len, BPF_MAXINSNS);</div><div>> +<span style="white-space:pre-wrap">            </span>tprintf("%hu", n); // bpf_debug requires <len>, prefix</div><div><br></div><div>Why you use %hu print int variable?</div></div></blockquote><div><br></div><div>Good point. Logically it cannot be larger thhan BPF_MAXINSN, so I can either use uint, or just printf with %d.</div><div>Using %d is preferred, am I correct?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>> +<span style="white-space:pre-wrap">              </span>for (i=0; i<n; i++) {</div><div>> +<span style="white-space:pre-wrap">                   </span>struct bpf_filter_block filter;</div><div>> +<span style="white-space:pre-wrap">                    </span>tfetch_mem(tcp, addr + i*sizeof(filter),</div><div>> +<span style="white-space:pre-wrap">                                   </span>sizeof(filter), &filter);</div><div>> +<span style="white-space:pre-wrap">                      </span>tprintf(",%u %u %u %u", filter.code, filter.jt,</div><div>> +<span style="white-space:pre-wrap">                                          </span>filter.jf, filter.k);</div><div>> +<span style="white-space:pre-wrap">              </span>}</div><div>> +<span style="white-space:pre-wrap">          </span>if (n < len)</div><div>> +<span style="white-space:pre-wrap">                    </span>tprints("...");</div><div><br></div><div>We can call the print_array to do the same thing.  Why you want to print in this</div><div>raw format?</div></div></blockquote><div>Because:</div><div>1. We want a raw format with minimal interpretation, like in other cases.</div><div>2. This is the only format accepted by the kernel's tools. User can easily copy and paste it to bpf_debug, and then disassemble it, run it, or print a C array enabling him to compile it to his own program. It is not better or worse than any other raw format, but it enable interoperability with kernel's current bpf tooling.</div><div>It was useful for me, when I had to debug the output of libseccomp once.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>>  <span style="white-space:pre-wrap">   </span>} else {</div><div>>  <span style="white-space:pre-wrap">          </span>struct bpf_filter_block_data fbd = { .fn = print_k };</div><div>>  <span style="white-space:pre-wrap">             </span>struct bpf_filter_block filter;</div><div>> </div><div><br></div><div>[1] <a href="https://strace.io/wiki/NewContributorGuide" target="_blank">https://strace.io/wiki/NewContributorGuide</a></div><div>--</div><div>Chen Jingpiao</div></div>
-- <br>
Strace-devel mailing list<br>
<a href="mailto:Strace-devel@lists.strace.io" target="_blank">Strace-devel@lists.strace.io</a><br>
<a href="https://lists.strace.io/mailman/listinfo/strace-devel" rel="noreferrer" target="_blank">https://lists.strace.io/mailman/listinfo/strace-devel</a><br>
</blockquote></div></div></div>