# How to Backtrace Functions?



## dkovacevic (Sep 28, 2017)

When getaddrinfo() is called, I'd like to be able to stop the request from completing before res_nquery is called, stemming from a "permissions" concern.



> On DragonflyBSD, NetBSD and FreeBSD, the "name-service switch dispatcher" configured in /etc/nsswitch.conf is used to select which sources for hostname lookups to use and what order to use them.



"...is used to select which sources..." - is used *by what *to select which sources?

I've looked at https://www.freebsd.org/cgi/man.cgi?query=nsdispatch, and it looks like a better place to implement security related code than res_nquery, but the impression I have of the "name-service switch dispatcher routine" is that the *decision* *to go through with dispatch* has already been made sometime before that point.

Maybe a better question / line of thinking: when I call getaddrinfo(), how do I trace that call back, one step at a time, to res_nquery?


----------



## dkovacevic (Sep 28, 2017)

If I put a ton of print statements in libc code, and then compile the FreeBSD kernel, will I be able to see those statements in the root console?


----------



## sko (Sep 29, 2017)

dkovacevic said:


> Maybe a better question / line of thinking: when I call getaddrinfo(), how do I trace that call back, one step at a time, to res_nquery?


This should be exactly what DTrace(1) was made for: Probing the running code/system and understanding what it does (or fails to do).

FreeBSD Handbook on Dtrace: https://www.freebsd.org/doc/handbook/dtrace.html
The DTrace guide on dtrace.org: http://dtrace.org/guide/


----------



## dkovacevic (Sep 29, 2017)

sko said:


> This should be exactly what DTrace(1) was made for: Probing the running code/system and understanding what it does (or fails to do).
> 
> FreeBSD Handbook on Dtrace: https://www.freebsd.org/doc/handbook/dtrace.html
> The DTrace guide on dtrace.org: http://dtrace.org/guide/



That looks useful, thank you.


----------



## _martin (Oct 28, 2017)

Dtrace is definitely good, but good old ltrace(1) is your friend here too. It gives you general idea what is being called.


----------

