theKernel 10.0
Loading...
Searching...
No Matches
MkObjectLog.cs
Go to the documentation of this file.
1
9/* LABEL-NO */
10
11/*****************************************************************************/
12/* */
13/* read */
14/* */
15/*****************************************************************************/
16
17using System;
18using System.Runtime.InteropServices;
19using Mk = csmkkernel.MkKernel;
20
21namespace csmkkernel {
22
23 public partial class MkObjectC {
24
25 public static int getPId() {
26 return System.Diagnostics.Process.GetCurrentProcess().Id;
27 }
28
29 public static int getTId() {
30 return System.Threading.Thread.CurrentThread.ManagedThreadId;
31 }
32
33 public static string getStackTrace(int level=2) {
34 return Environment.StackTrace;
35 }
36
37 public static string getCallerProc(int level=2) {
38 var sf = new System.Diagnostics.StackFrame(level);
39 return sf.GetMethod().Name;
40 }
41
42 public static int getCallerLine(int level=2) {
43 var sf = new System.Diagnostics.StackFrame(level);
44 return sf.GetFileLineNumber();
45 }
46
47 public static string getCallerFile(int level=2) {
48 var sf = new System.Diagnostics.StackFrame(level,true);
49 return sf.GetFileName();
50 }
51
52 internal static void getCallerStack(ref string func, ref string file, ref int line, int level=2) {
53 if (func != null && file != null && line != -1) return;
54 var sf = new System.Diagnostics.StackFrame(level,true);
55 if (func == null) {func = sf.GetMethod().Name;}
56 if (file == null) {file = sf.GetFileName();}
57 if (line == -1) {line = sf.GetFileLineNumber();}
58 }
59
60#if CLR_DEBUG
61 public static void SF(string msg, string name = null, int framelvl=1) {
62 if (name == null) { name = getCallerProc(); }
63 Console.Error.WriteLine("[pid=" + getPId() + ",tid=" + getTId() + ",caller={0,-25}] -> {1,-15} = " + msg,
64 getCallerProc(framelvl+1), name);
65 }
66 public static void printVal(IntPtr ptr, string name=null, int framelvl=1) {
67 if (name == null) { name = getCallerProc(); }
68 if (ptr == IntPtr.Zero) {
69 SF("null", name, framelvl+1);
70 } else {
71 SF("0x" + ptr.ToString("x"), name, framelvl+1);
72 }
73 }
74 public static void printVal(byte bol, string name=null, int framelvl=1) {
75 if (name == null) { name = getCallerProc(); }
76 SF(bol.ToString(), name, framelvl+1);
77 }
78 public static void printVal(bool bol, string name=null, int framelvl=1) {
79 if (name == null) { name = getCallerProc(); }
80 SF(bol.ToString(), name, framelvl+1);
81 }
82 public static void printVal(object id, string name=null, int framelvl=1) {
83 if (name == null) { name = getCallerProc(); }
84 if (id == null) {
85 SF("type=null " + id.GetType().ToString(), name, framelvl+1);
86 } else {
87 SF("type=" + id.GetType().ToString() + ", value=" + id, name, framelvl+1);
88 }
89 }
90 public static void printVal(string id, string name=null, int framelvl=1) {
91 if (name == null) { name = getCallerProc(); }
92 SF(id.ToString(), name, framelvl+1);
93 }
94 public static void printTyp(IntPtr id, string name=null, int framelvl=1) {
95 if (name == null) { name = getCallerProc(); }
96 if (id == IntPtr.Zero) {
97 SF("NULL", name, framelvl+1);
98 } else {
99 SF(MkObjectC.Name(IntPtr.Zero, id), name, framelvl+1);
100 //Mk.MqLogObjDetail(id,IntPtr.Zero,0,name,0);
101 }
102 }
103 public static void printStack(string name=null, int framelvl=1) {
104 if (name == null) { name = getCallerProc(); }
105 System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true);
106 for(int i =framelvl; i< st.FrameCount; i++ )
107 {
108 // Note that at this level, there are four
109 // stack frames, one for each method invocation.
110 System.Diagnostics.StackFrame sf = st.GetFrame(i);
111 SF(String.Format("[{0}] {1}",i ,sf.GetMethod()), name, framelvl+1);
112 }
113 }
114 public static void printTyp(MkObjectC obj, string name=null, int framelvl=1) {
115 printTyp(obj.hdl,name,framelvl+1);
116 }
117 public static void M0(string name="M0") { SF("M0000000000000",name,2); }
118 public static void M1(string name="M1") { SF("M1111111111111",name,2); }
119 public static void M2(string name="M2") { SF("M2222222222222",name,2); }
120 public static void M3(string name="M3") { SF("M3333333333333",name,2); }
121 public static void M4(string name="M4") { SF("M4444444444444",name,2); }
122 public static void M5(string name="M5") { SF("M5555555555555",name,2); }
123 public static void M6(string name="M6") { SF("M6666666666666",name,2); }
124 public static void M7(string name="M7") { SF("M7777777777777",name,2); }
125 public static void M8(string name="M8") { SF("M8888888888888",name,2); }
126 public static void M9(string name="M9") { SF("M9999999999999",name,2); }
127 public static void MA(string name="MA") { SF("MAAAAAAAAAAAAA",name,2); }
128 public static void MB(string name="MB") { SF("MBBBBBBBBBBBBB",name,2); }
129 public static void MC(string name="MC") { SF("MCCCCCCCCCCCCC",name,2); }
130 public static void MD(string name="MD") { SF("MDDDDDDDDDDDDD",name,2); }
131 public static void ME(string name="ME") { SF("MEEEEEEEEEEEEE",name,2); }
132#endif // CLR_DEBUG
133 }
134
135 public partial class MkObjectC
136 {
137
140
141#if CLR_DEBUG
142
143 private void SL(string txt) {
144 IntPtr caller_cstr = Marshal.StringToHGlobalAnsi(getCallerProc());
145 IntPtr message_cstr = Marshal.StringToHGlobalAnsi(this + ":\n" + txt + "\n");
146 Mk.MkLogC(IntPtr.Zero,hdl,message_cstr,0,caller_cstr);
147 Marshal.FreeHGlobal(message_cstr);
148 Marshal.FreeHGlobal(caller_cstr);
149 }
150
151 public void L0() { SL("0000000000000"); }
152 public void L1() { SL("1111111111111"); }
153 public void L2() { SL("2222222222222"); }
154 public void L3() { SL("3333333333333"); }
155 public void L4() { SL("4444444444444"); }
156 public void L5() { SL("5555555555555"); }
157 public void L6() { SL("6666666666666"); }
158 public void L7() { SL("7777777777777"); }
159 public void L8() { SL("8888888888888"); }
160 public void L9() { SL("9999999999999"); }
161 public void LA() { SL("AAAAAAAAAAAAA"); }
162 public void LB() { SL("BBBBBBBBBBBBB"); }
163 public void LC() { SL("CCCCCCCCCCCCC"); }
164 public void LE() { SL("EEEEEEEEEEEEE"); }
165
166 public void printL(string name, Object val ) { SL("["+name + ":" + val + "]"); }
167#endif // CLR_DEBUG
168
170
171 } // END - class "MqContextC"
172
173} // END - namespace "csmkkernel.mqmsgque"
174
csmkkernel.MkKernel Mk
MkKernel PACKAGE - The package is the toplevel structure of the Programming-Language-Micro-Kernel (PL...
MkObjectC - class known as obj or object is used as base-class type for a Programming-Language-Micro-...
static int getCallerLine(int level=2)
static string getCallerProc(int level=2)
static string getStackTrace(int level=2)
static string getCallerFile(int level=2)
static int getPId()
static int getTId()
override string ToString()
C#: string inst.ToString() → C-API String-Slot - returns the string representation of the inst ...
Definition MkObjectC.cs:612