]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: simplify Lua stack dump procedure
authorPatrick Donnelly <pdonnell@redhat.com>
Tue, 13 Oct 2020 16:47:57 +0000 (09:47 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 14 Oct 2020 13:50:53 +0000 (06:50 -0700)
Lua has methods which help with printing values as strings.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/rgw/rgw_lua_utils.cc

index 45ef0e8e5e21d96e02b56ca335b90400ef98c70a..c3b380f7957248dd89077b23e3285fe3571403c2 100644 (file)
@@ -36,29 +36,12 @@ void create_debug_action(lua_State* L, CephContext* cct) {
 }
 
 void stack_dump(lua_State* L) {
-       auto i = lua_gettop(L);
+  int top = lua_gettop(L);
   std::cout << std::endl << " ----------------  Stack Dump ----------------" << std::endl;
-  std::cout << "Stack Size: " << i << std::endl;
-  while (i > 0) {
-    const auto t = lua_type(L, i);
-    switch (t) {
-      case LUA_TNIL:
-        std::cout << i << ": nil" << std::endl;
-        break;
-      case LUA_TSTRING:
-        std::cout << i << ": " << lua_tostring(L, i) << std::endl;
-        break;
-      case LUA_TBOOLEAN:
-        std::cout << i << ": " << lua_toboolean(L, i) << std::endl;
-        break;
-      case LUA_TNUMBER:
-        std::cout << i << ": " << lua_tonumber(L, i) << std::endl;
-        break;
-      default: 
-        std::cout << i << ": " << lua_typename(L, t) << std::endl;
-        break;
-    }
-    i--;
+  std::cout << "Stack Size: " << top << std::endl;
+  for (int i = 1, j = -top; i <= top; i++, j++) {
+    std::cout << "[" << i << "," << j << "]: " << luaL_tolstring(L, i, NULL) << std::endl;
+    lua_pop(L, 1);
   }
   std::cout << "--------------- Stack Dump Finished ---------------" << std::endl;
 }