Add different handler libs handling 84/111884/12
authorAlexander Aksenov <a.aksenov@samsung.com>
Mon, 23 Jan 2017 18:09:28 +0000 (21:09 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Fri, 2 Jun 2017 11:27:48 +0000 (14:27 +0300)
This commit is related with same name commits in swap-manager
and swap-modules.

Change-Id: I89e99ab1dcc8d1326c9e655c1d530960896a889f
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
helper/api_names.txt
probe_capi/api_names.txt
probe_event/api_names.txt
probe_file/api_names.txt
probe_graphics/api_names.txt
probe_memory/api_names.txt
probe_socket/api_names.txt
probe_thread/api_names.txt
probe_ui/api_names.txt
scripts/gen_headers.py

index d01bcaa..e46648a 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/da_probe_tizen.so"
 #filename "daforkexec.c"
 #lib "/__lib_prefix__/libc.so.6"
 #feature ---
index 09ee4b6..6a20a4d 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/swap_probe_capi.so"
 #filename "capi_appfw.c"
 #lib "/usr/__lib_prefix__/libcapi-appfw-application.so.0"
 #feature ---
index 1798301..47165b6 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/swap_probe_event.so"
 #filename "gesture.cpp"
 #lib "???"
 #feature ---
index 67939e7..21729a2 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/da_probe_tizen.so"
 #filename "da_io_stdc.c"
 #lib "/__lib_prefix__/*"
 #feature FL_FILE_API_PROBING_PRELOAD
index c90bbc3..2636dc2 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/swap_probe_graphics.so"
 #filename "da_evas_gl.c"
 #lib "/usr/__lib_prefix__/libevas.so.1"
 #feature FL_OPENGL_API_PROBING_PRELOAD
index 8c810e5..73bf8b1 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/da_probe_tizen.so"
 #filename "libdamemmanage.c"
 #lib "/__lib_prefix__/*"
 #feature FL_MEMORY_ALLOC_PROBING_PRELOAD
index be39839..6bfad9a 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/da_probe_tizen.so"
 #filename "libdasocket.c"
 #lib "/__lib_prefix__/*"
 #feature FL_NETWORK_API_PROBING_PRELOAD
index c8f1fb1..e74f0a9 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/da_probe_tizen.so"
 #filename "libdasync.c"
 #lib "/__lib_prefix__/*"
 #feature FL_THREAD_API_PROBING_PRELOAD
index bc8393c..e8dfae7 100644 (file)
@@ -1,3 +1,4 @@
+#handler "/usr/__lib_prefix__/swap_probe_ui.so"
 #filename "capi_capture.c"
 #lib "/usr/__lib_prefix__/libevas.so.1"
 #feature ---
index 478208d..0dd9f21 100755 (executable)
@@ -116,6 +116,11 @@ def __add_item(data_dict, dict_keys, data):
 
     return data_dict
 
+def __path_var_name_from_path(path):
+    var_name = os.path.basename(path)
+    var_name = os.path.splitext(var_name)[0]
+    var_name += "_path"
+    return var_name
 
 #################### Parsing api_names_all.txt #####################
 libs_in_dir = {}
@@ -146,6 +151,7 @@ def __parse_file(libs_data, file):
     filename_tag = "#filename"
     lib_tag = "#lib"
     feature_tag = "#feature"
+    handler_tag = "#handler"
 
     current_filename = ""
     current_libs = []
@@ -178,6 +184,9 @@ def __parse_file(libs_data, file):
             global defines
             dbg_log("defines[" + list[1] + "] = " + list[2])
             defines[list[1]] = list[2]
+        elif line[:8] == handler_tag:
+                current_handler = re.sub("\"", "", line.split()[1])
+                current_handler = current_handler.replace("__lib_prefix__", lib_prefix)
         elif line[:1] == "#":
                 #dbg_log("[WARN]: commented code : <" + line + ">")
                 continue
@@ -199,7 +208,7 @@ def __parse_file(libs_data, file):
                 dbg_log("[WARN]: Skip func <" + func + "> file <" + current_filename + "> lib <" + current_libs[0] + ">")
                 continue
 
-            libs_data = __add_item(libs_data, [current_libs, [func, [current_feature]]], (handler, probe_type))
+            libs_data = __add_item(libs_data, [current_handler, [current_libs, [func, [current_feature]]]], (handler, probe_type))
 
     dbg_log("<--- __parse_file")
     return libs_data
@@ -216,16 +225,23 @@ def parse_apis(func_list_file):
     return libs_data
 
 
-def parse_probe_lib(da_lib):
+def parse_probe_libs(data):
     dbg_log("parse_probe_lib")
-    return get_all_symbols(da_lib)
+    probe_libs = {}
+
+    for lib in data:
+        lib_to_parse = os.path.basename(lib)
+        probe_libs[lib] = get_all_symbols(lib_to_parse)
+
+    return probe_libs
 
 ####################################################################
 
 ################## Getting function's addresses ####################
 def __get_addr_by_funcname_handler(lib_data, funcname):
-    if funcname in lib_data:
-        return lib_data[funcname]
+    for lib in lib_data:
+        if funcname in lib_data[lib]:
+            return lib_data[lib][funcname]
     return None
 
 def __get_addr_by_funcname_lib(lib_data, funcname):
@@ -266,28 +282,29 @@ def get_function_search_error(function_name):
 def iterate_over_libs(data, probe_lib):
     dbg_log("iterate_over_libs")
     feature_dict = {}
-    for libname in data:
-        lib_data = get_all_symbols(libname)
-        if lib_data is None:
-            continue
-        for funcname in data[libname]:
-            addr = __get_addr_by_funcname_lib(lib_data, funcname)
-            if funcname not in function_errors:
-                function_errors[funcname] = ERR_HANDLER_NO_FEATURE;
+    for handler in data:
+        for libname in data[handler]:
+            lib_data = get_all_symbols(libname)
+            if lib_data is None:
+                continue
+            for funcname in data[handler][libname]:
+                addr = __get_addr_by_funcname_lib(lib_data, funcname)
+                if funcname not in function_errors:
+                    function_errors[funcname] = ERR_HANDLER_NO_FEATURE;
 
-            for feature in data[libname][funcname]:
-                if function_errors[funcname] == ERR_HANDLER_NO_FEATURE:
-                    function_errors[funcname] = ERR_HANDLER_FOUND_BUT_CANNOT_BE_LINKED;
+                for feature in data[handler][libname][funcname]:
+                    if function_errors[funcname] == ERR_HANDLER_NO_FEATURE:
+                        function_errors[funcname] = ERR_HANDLER_FOUND_BUT_CANNOT_BE_LINKED;
 
-                handler_addr = __get_addr_by_funcname_handler(probe_lib, data[libname][funcname][feature][0])
+                    handler_addr = __get_addr_by_funcname_handler(probe_lib, data[handler][libname][funcname][feature][0])
 
-                if handler_addr is None:
-                    function_errors[funcname] = ERR_HANDLER_NOT_FOUND_IN_LD_LIB
-                    continue
+                    if handler_addr is None:
+                        function_errors[funcname] = ERR_HANDLER_NOT_FOUND_IN_LD_LIB
+                        continue
 
-                if addr is not None:
-                    feature_dict = __add_item(feature_dict, [feature, [libname, [funcname]]], (addr, handler_addr, data[libname][funcname][feature][1]))
-                    function_errors[funcname] = ERR_NO;
+                    if addr is not None:
+                        feature_dict = __add_item(feature_dict, [handler, [feature, [libname, [funcname]]]], (addr, handler_addr, data[handler][libname][funcname][feature][1]))
+                        function_errors[funcname] = ERR_NO;
     return feature_dict
 
 ####################################################################
@@ -376,53 +393,63 @@ def __print_probes(file, func, addr_list, handler, type):
 
     return probes_cnt
 
-def __print_feature_list(file, features_cnt, features_list_dict):
+def __print_feature_list(file, features_cnt, features_list_dict, handlers_list):
     file.write("int feature_to_data_count = " + str(features_cnt) + ";\n")
+    for handler in handlers_list:
+        handler_var = __path_var_name_from_path(handler)
+        file.write("char " + handler_var +"[] = \"" + handler + "\";\n")
     file.write("struct feature_list_t feature_to_data[] = {\n")
     for feature in features_list_dict:
-        file.write("\t{.feature_value_0 = 0, .feature_value_1 = " + feature + ", .feature_ld = &" + features_list_dict[feature] + "},\n")
+        handler_var = __path_var_name_from_path(features_list_dict[feature][1])
+        if "LSAN" in feature:
+            file.write("\t{.feature_value_0 = " + feature + ", .feature_value_1 = 0, .feature_ld = &" + features_list_dict[feature][0] + ", .feature_handler = &" + handler_var + "},\n")
+        else:
+            file.write("\t{.feature_value_0 = 0, .feature_value_1 = " + feature + ", .feature_ld = &" + features_list_dict[feature][0] + ", .feature_handler = &" + handler_var + "},\n")
     file.write("};\n")
 
 def __print_features(file, data):
     features_cnt = 0
     features_list_dict = {}
+    handlers_list = []
+
+    for handler in data:
+        handlers_list.append(handler)
+        for feature in data[handler]:
+            write_feature = feature
+            if write_feature == "---":
+                write_feature = "NOFEATURE"
+            feature_lib_list = write_feature + "_lib_list"
+            feature_list = write_feature + "_list"
+            if features_list_dict is None:
+                features_list_dict = {write_feature : (feature_list, handler)}
+            else:
+                features_list_dict[write_feature] = (feature_list, handler)
 
-    for feature in data:
-        write_feature = feature
-        if write_feature == "---":
-            write_feature = "NOFEATURE"
-        feature_lib_list = write_feature + "_lib_list"
-        feature_list = write_feature + "_list"
-        if features_list_dict is None:
-            features_list_dict = {write_feature : feature_list}
-        else:
-            features_list_dict[write_feature] = feature_list
-
-        __print_feature_begin(file, write_feature)
-        features_cnt += 1
-        libs_in_feature = {}
+            __print_feature_begin(file, write_feature)
+            features_cnt += 1
+            libs_in_feature = {}
 
-        for lib in data[feature]:
-            # skip /emul/*
-            if lib.startswith('/emul/'):
-                continue
-            lib_feature_name = re.sub("\.", "_", re.sub("-", "__", os.path.basename(lib)))
-            lib_feature_name = write_feature + "_" + lib_feature_name
-            __print_lib_begin(file, lib, lib_feature_name)
-            probes_in_feature = 0
+            for lib in data[handler][feature]:
+                # skip /emul/*
+                if lib.startswith('/emul/'):
+                    continue
+                lib_feature_name = re.sub("\.", "_", re.sub("-", "__", os.path.basename(lib)))
+                lib_feature_name = write_feature + "_" + lib_feature_name
+                __print_lib_begin(file, lib, lib_feature_name)
+                probes_in_feature = 0
 
-            for func in data[feature][lib]:
-                probes_in_feature += __print_probes(file, func, data[feature][lib][func][0], data[feature][lib][func][1], data[feature][lib][func][2])
+                for func in data[handler][feature][lib]:
+                    probes_in_feature += __print_probes(file, func, data[handler][feature][lib][func][0], data[handler][feature][lib][func][1], data[handler][feature][lib][func][2])
 
-            if libs_in_feature is None:
-                libs_in_feature = {lib : (probes_in_feature, lib_feature_name)}
-            else:
-                libs_in_feature[lib] = (probes_in_feature, lib_feature_name)
-            __print_lib_end(file)
+                if libs_in_feature is None:
+                    libs_in_feature = {lib : (probes_in_feature, lib_feature_name)}
+                else:
+                    libs_in_feature[lib] = (probes_in_feature, lib_feature_name)
+                __print_lib_end(file)
 
-        __print_feature_end(file, libs_in_feature, feature_lib_list, feature_list)
+            __print_feature_end(file, libs_in_feature, feature_lib_list, feature_list)
 
-    __print_feature_list(file, features_cnt, features_list_dict)
+    __print_feature_list(file, features_cnt, features_list_dict, handlers_list)
 
 def __print_probe_el_t(file):
     file.write("struct ld_probe_el_t {\n")
@@ -450,6 +477,7 @@ def __print_feature_list_t(file):
     file.write("\tenum feature_code_0 feature_value_0;\n")
     file.write("\tenum feature_code_1 feature_value_1;\n")
     file.write("\tstruct ld_feature_list_el_t *feature_ld;\n")
+    file.write("\tchar *feature_handler;\n")
     file.write("};\n")
 
 def __print_types(file):
@@ -535,7 +563,7 @@ if parse_elf.init_library() != 0:
     exit(1)
 
 data = parse_apis(func_list_file)
-probe_lib = parse_probe_lib(da_lib)
+probe_lib = parse_probe_libs(data)
 feature_dict = iterate_over_libs(data, probe_lib)
 generate_headers(feature_dict, da_inst_dir, da_lib, probe_lib)