massemanet/eper

How to make redbug print out records as records and not as tuples?

mattiasw2 opened this issue · 3 comments

What is the trick?

Alas, there is no trick. The current version of redbug does not support this.
Reason (short), there is no good way to do it.
Reason (long); the record "feature" is a pre-processor hack. Thus, it's not possible to get record info from the loaded beam code. One would have to either find and parse the source code, or rely on the abstract code chunk on the beam file. In either case, that implies not only a file system access, but one also has to figure out in which .beam/.erl file the record is defined. Note that not even searching for a given record in all .beam files will work (since there is nothing that prevents multiple .erl files from declaring different records with the same name.)
Having said that, one could do a best-effort. Assuming that the record is defined in the module(s) we're redbugging, and the .beam file can be found, and the .beam file has abstract code, and we indicate that the overhead is acceptable by setting a flag, it could be made to work.
I'll put it on the feature request list.

For future reference; a truly awful one-liner to get record info from the Abst chunk (e/2 is an alias for element/2).

[{e(1,e(4,R)),[e(3,e(3,E))||E<-e(2,e(4,R))]}||R<-e(2,binary_to_term(e(2,e(1,e(2,e(2,beam_lib:chunks(code:which(file),["Abst"]))))))),element(3,R)==record].

Thanks for thinking about it. I really like redbug, once I learned tricks like

redbug:start("te_experiments:generate_ocaml({apply, Op, Args}, TAS)").

I stopped adding io:format to the code all the time.