Logging to fbterminal (was Re: Building programs with MODE=shared in L4Re)

Paul Boddie paul at boddie.org.uk
Sat May 19 23:16:25 CEST 2018

On Monday 14. May 2018 22.06.06 Paul Boddie wrote:
> On Monday 14. May 2018 21.18.04 Adam Lackorzynski wrote:
> > You can set LD_DEBUG=1 in the environment of your program to make the
> > dynamic loader tell you something. LD_TRACE_LOADED_OBJECTS=1 might also
> > be of help. Add enviroment variable settings after the program's
> > cmdline: ...:start({ ...}, "rom/myprog arg", { LD_DEBUG=1, ... });
> I imagine I could direct log information to a suitable program for display
> on the screen rather than via the serial console. Can I do this using
> something like fbterminal? I'm still getting to grips with the different
> mechanisms accessed and exposed by the different programs.

Maybe the matter of configuring fbterminal as a logging destination is obvious 
to those better acquainted with L4Re, but I eventually figured it out in a 
way. What I needed to do is to provide a different "log" capability to the 
hello program, but this is perhaps easier said than done.

According to the documentation...


...it is supposed to be possible to indicate a log factory that creates a 
suitable object using the "log_fab" property/attribute of the loader.

Looking at the Lua code (pkg/l4re-core/ned/server/src/ned.lua), the 
App_env:log function seems to be the thing that gets called, returning the 
desired capability:

return self.loader.log_fab:create(Proto.Log, table.unpack(self.log_args));

While, I guess I might make a suitable loader available with code that looks 
like this...

local l2 = L4.Loader.new({loader = l, log_fab = term});

...and then use it to start the hello program...

    log = { "hello", "b" },

...the challenge is to specify something that can *create* the logging 
destination. In my .cfg script, "term" is actually the IPC gate (or "channel") 
capability exposing the fbterminal:

local term = l:new_channel();

    caps = {
      fb = mag_caps.svc:create(L4.Proto.Goos, "g=800x460+0+0",
      term = term:svr(),

So, as far as I can see, I would need something that acts as a factory capable 
of providing a fbterminal capability when its create method is invoked 
(specifying the log protocol). This seems like a lot of effort.

It then occurred to me that I only really want a way of presenting the "term" 
capability to the hello program. Since this isn't obviously possible in the 
loader, I modified the App_env:log function to support an additional case:

  if self.log_cap then
    return self.log_cap
  elseif self.loader.log_fab == nil or self.loader.log_fab.create == nil then
    error ("Starting an application without valid log factory", 4);

Thus, if "log_cap" is indicated when starting a program, it just uses this 
instead of trying to conjure up another capability. So the hello program is 
started as follows:

    log_cap = term,

This manages to log to fbterminal, much to my relief. I hope this helps anyone 
else who struggled with this or just wondered about it.


More information about the l4-hackers mailing list