summary refs log tree commit diff
path: root/pkgs/lib/debug.nix
diff options
context:
space:
mode:
authorMarc Weber <marco-oweber@gmx.de>2009-03-06 23:21:35 +0000
committerMarc Weber <marco-oweber@gmx.de>2009-03-06 23:21:35 +0000
commit08e1c08bc7198a218f60ef5534050c1f0cc2a0fe (patch)
treec9c2ee13857310d805d2baa3ba97b9c1e4bc7a6a /pkgs/lib/debug.nix
parent49b115132d3f5e7c83f50a0430a571a217eee7fb (diff)
downloadnixpkgs-08e1c08bc7198a218f60ef5534050c1f0cc2a0fe.tar
nixpkgs-08e1c08bc7198a218f60ef5534050c1f0cc2a0fe.tar.gz
nixpkgs-08e1c08bc7198a218f60ef5534050c1f0cc2a0fe.tar.bz2
nixpkgs-08e1c08bc7198a218f60ef5534050c1f0cc2a0fe.tar.lz
nixpkgs-08e1c08bc7198a218f60ef5534050c1f0cc2a0fe.tar.xz
nixpkgs-08e1c08bc7198a218f60ef5534050c1f0cc2a0fe.tar.zst
nixpkgs-08e1c08bc7198a218f60ef5534050c1f0cc2a0fe.zip
moved debugging functions into lib module "debug"
svn path=/nixpkgs/trunk/; revision=14430
Diffstat (limited to 'pkgs/lib/debug.nix')
-rw-r--r--pkgs/lib/debug.nix24
1 files changed, 23 insertions, 1 deletions
diff --git a/pkgs/lib/debug.nix b/pkgs/lib/debug.nix
index f1f366d065b..55d6a0d1b65 100644
--- a/pkgs/lib/debug.nix
+++ b/pkgs/lib/debug.nix
@@ -14,5 +14,27 @@ rec {
 
   addErrorContextToAttrs = lib.mapAttrs (a : v : lib.addErrorContext "while evaluating ${a}" v);
 
+  debugVal = if builtins ? trace then x: (builtins.trace x x) else x: x;
+  debugXMLVal = if builtins ? trace then x: (builtins.trace (builtins.toXML x) x) else x: x;
 
-}
\ No newline at end of file
+  # this can help debug your code as well - designed to not produce thousands of lines
+  traceWhatis = x : __trace (whatis x) x;
+  traceMarked = str: x: __trace (str + (whatis x)) x;
+  attrNamesToStr = a : lib.concatStringsSep "; " (map (x : "${x}=") (__attrNames a));
+  whatis = x :
+      if (__isAttrs x) then
+          if (x ? outPath) then "x is a derivation, name ${if x ? name then x.name else "<no name>"}, { ${attrNamesToStr x} }"
+          else "x is attr set { ${attrNamesToStr x} }"
+      else if (__isFunction x) then "x is a function"
+      else if (x == []) then "x is an empty list"
+      else if (__isList x) then "x is a list, first item is : ${whatis (__head x)}"
+      else if (x == true) then "x is boolean true"
+      else if (x == false) then "x is boolean false"
+      else if (x == null) then "x is null"
+      else "x is probably a string starting, starting characters: ${__substring 0 50 x}..";
+  # trace the arguments passed to function and its result 
+  traceCall  = n : f : a : let t = n2 : x : traceMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a));
+  traceCall2 = n : f : a : b : let t = n2 : x : traceMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b));
+  traceCall3 = n : f : a : b : c : let t = n2 : x : traceMarked "${n} ${n2}:" x; in t "result" (f (t "arg 1" a) (t "arg 2" b) (t "arg 3" c));
+
+}